# Thread: Guessing game - loop counting

1. ## Guessing game - loop counting

Hey guys. Basically I am writing a program with a menu to select various games. Then write the code for the individual games. Oh and this is not a homework assignment. More of a practice/boredum project. Relatively new to programming but trying to learn

Anyway, I am wondering how do I implement a check to see how many times the user entered a guess and if it exceeds it, move onto the next do loop. I will post part of the code for the guessing game portion of my program as it stands now. I tried to use while loops but I am not sure I used them write because it messed up the output and didnt do what I wanted. It does work now the way it is. Just trying to put the checks in.

Any Suggestions?

Code:
```    do
{
num[1]=rand()%10+1;
num[2]=rand()%100+1;
num[3]=rand()%1000+1;
num[4]=rand()%10000+1;
num[5]=rand()%100000+1;
do
{

cout << "\nPick a number between 1 and 10: ";
cin >> guess;

if (guess>num[1])
{
cout << "\nToo High. Guess Again. ";
}
else if (guess<num[1])
{
cout << "\nToo Low. Guess Again. ";
tries++;
}
if (guess==num[1])
{
cout << "\nCongratulations, you guessed the answer correct\n";
}

}
while (guess!=num[1]);

do
{
cout << "\nPick a number between 1 and 100: ";
cin >> guess;
if (guess>num[2])
{
cout << "\nToo High. Guess Again. ";
}
else if (guess<num[2])
{
cout << "\nToo Low. Guess Again. ";
}
if (guess==num[2])
{
cout << "\nCongratulations, you guessed the answer correct\n";
}
}
while (guess!=num[2]);

.... goes on  like that till num[5]

cout << "\nWould you like to play again? (y|n) \n";
contin=getch();

}```

2. Every time you do a cin to get a guess, increment a counter. When the counter exceeds your limit, leave the loop.

3. thanks man. didn't even think of putting the check in the while statement after each do loop. Works now