Okay so I'm trying to do one of the beginner programs which tells a user not to type a certain number. The user then types a number and if it isn't that certain number they have to try again. They do this until they actually type the number they were told not to type. Here is what I have so far and I face two problems: The very first input the user gives, for some reason isn't registering or something.. second, when the for loop is ran for the tenth time, the program terminates. This is fine but I also wanted it to print a message on screen before it terminated.. Please help and sorry that I'm such a newbie!
Yeah, what TheIdeasMan said. It's safer, in case you change i within the loop or something like that.
Consider the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// This loop will run three times, as at the end of the third iteration, i is 11.
for(int i=0; i < 10; i++)
{
cout << "First i: " << i << endl;
i+=3;
cout << "Second i: " << i << endl;
}
// This loop will run a lot more than three times.
for(int i=0; i != 10; i++)
{
cout << "First i: " << i << endl;
i+=3;
cout << "Second i: " << i << endl;
}