Hello, I am working on some beginer exercises that were listed here on the forums. But i am get an error during compile at an for statment. When the compiler gets to the braces at the start of the statment, it says 'i undeclared identifier'.
Here is the code that i have. I have tested the for loop by itself and it works, but here no dice.
I suppose he's trying to get the user to enter 5 9 times (at least that's what he's doing right now)? I don't know, if I did run that program I would probably just hit ctrl+c cause I'd assume it is broken.
for (int i=0; i<10; i++)
it is after this entering the block, that i get an error message in my compiler. It says 'i' undeclared identifier.
Im at a loss, because the syntax is right.
#include <iostream>
usingnamespace std;
int main()
{
int chNumber = 0;
for (int i=0; i<10; ++i)
{
cout << "\nEnter a number other than 5.\n";
cin >> chNumber;
if (chNumber == 5){
cout << "\nHEY!! You weren't suppose to enter 5.\n";
break;
}
}
cout << "\nNow the exercise is over.\n";
return 0;
}
I modified your program a little. This version should work. You didn't need the while loop after all...
hansr99;
yes i wrote that, i am working through exersices that are listed on this site. http://www.cplusplus.com/forum/articles/12974/
I am just starting to learn c++ and this is one of my first problems to solve.