#include <iostream>
usingnamespace std;
int main()
{
for(int i = 0; i < 10; i++)
{
cout << "i is now " << i << endl;
}
int x = 0;
while(x < 10)
{
cout << "x is now " << x << endl;
x++;
}
return 0;
}
The differences being the initialization needs to happen before and outside the while loop, otherwise you'll have an issue with variables being out of scope, and the expression will be the final statement (or statements).
guessNum = 0;
do
{
cout << " What would you like to guess? \n";
cin >> guess;
if(guess < numPicked)
cout << "\nYou guessed too low! \n \n";
elseif (guess > numPicked)
cout << "\nYou guessed too high! \n \n";
guessNum++;
}while (guess != numPicked);
All I did was
1. put the initialization before, and outside the loop
2. moved the condition to a while loop at the moved
3. Add the expression as the final statement of the loop