I have trouble running this program. I get an error saying "end of file found before the left brace '{' "
#include <iostream>
using namespace std;
int main()
{
int num, product = 10;
cout << "Enter value "
<<"(enter -1 if done) : ";
cin >> num;
cout << endl;
while (num != -1)
{
product = product * num;
cout << "The product is " << product << endl;
break;
cout << "Enter next value "
<< "(enter -99 if done) : ";
cin >> num;
}
Add a closing bracket on line 23:
#include <iostream>
using namespace std;
int main()
{
int num, product = 10;
cout << "Enter value "
<<"(enter -1 if done) : ";
cin >> num;
cout << endl;
while (num != -1)
{
product = product * num;
cout << "The product is " << product << endl;
break;
cout << "Enter next value "
<< "(enter -99 if done) : ";
cin >> num;
}
} //<---------------------------------
Yep, your "while" loop has braces, but your "main" function is missing a closing brace. Hence, the error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
using namespace std;
int main()
{
int num, product = 10;
cout << "Enter value "
<<"(enter -1 if done) : ";
cin >> num;
cout << endl;
while (num != -1)
{
product = product * num;
cout << "The product is " << product << endl;
break;
cout << "Enter next value "
<< "(enter -99 if done) : ";
cin >> num;
}
return 0;
}
|
Also, take a walk through your loop and notice that it will never run more than once.
Last edited on