0

I keep getting an extra prompt, how can I declare my variables inside of my for loop?

// Sample program to demonstrate pre=test loop // CSCI 1010 Practice Problems 6 #include<iostream> using namespace std; int main() { double number1, smallnumber, count, limit; cout << "How many numbers would you like to enter" << endl; cin >> limit; cout << "Enter a number or enter (-1) to exit the program " << endl; cin >> smallnumber; if (smallnumber != -1) { for (count = 0; count <= limit; count++) { cout << "Enter a number or enter (-1) to exit the program " << endl; cin >> number1; if (number1 < smallnumber) { smallnumber = number1; } } } cout << smallnumber << endl; system("pause"); return 0;

18th Sep 2017, 3:49 PM
Christopher Albert
Christopher Albert - avatar
1 Resposta
+ 5
As I understood, what you wish to do is read n entries of data or till -1 is encountered. In your loop, count goes from 0 to n, thus loop runs for n+1 terms. So either make count start from 1 (for(int count = 1;count <= n;count ++)) or set count less than n (for(int count = 0;count < n;count ++))
18th Sep 2017, 4:46 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar