wont stop

how do i make this stop printing out the same thing?

#include <iostream>
#include <ctime>

using namespace std;

int main()
{
char answer;
cout << " would you like to play a game (y/n)? " << endl;
cin >> answer;
while (toupper(answer) == 'Y')
{
int min = 1,max =10;
srand(static_cast <unsigned int> (time(0)));
int count = 1;
int num = rand() % 10 + 1;
int guess;
cout << " Guess a number between 1 and 10: " << endl;
cin >> guess;
while (guess != num)
{

cout << " Would you like play again (y/n)? " << endl;
}


for (int j = 0; j < 10; j++);
{
for (int i = 0; i < 10; i++);
{
cout << (rand() % (1 + max - min) + min) << endl;

}
cout << endl;
}
}

return 0;

}
Move srand(...) out of the while loop to the top of main().
closed account (48T7M4Gy)
Turn the power off?

The problem is guess and num are integers while you are asking the user for char answer to y/n
Last edited on
Change your while loop:
1
2
3
4
5
6
7
8
9
10
11
12
cin >> guess;
while (guess != num)
{

cout << " Would you like play again (y/n)? " << endl;
cin >> answer;
if(toupper(answer) == 'Y')
  cin >> guess;
else
  break;
}
Topic archived. No new replies allowed.