Loop will not stop?

My break; isn't ending the for statement. User should only get 3 choices but they get to input more than 3 times. Please let me know what i can do to fix this.

int playGame()
{
int count = 0;
int random = (rand() % 10) + 1;
int choice;

for (int i = 0; i < 3; i++) {
cout << "Guess the number 1-10: ";
cin >> choice;
if (random == choice) {
cout << "you guessed it right!" << endl;
count += 10;
break;
} else if (i == 3) {
cout << "you lose!" << endl;
count--;
break;
} else {
cout << "Guess again!" << endl;
}
}
return count;
}
The loop only iterates 3 times. It may seem like more if you call the function back-to-back as it is never possible for i == 3 to evaluate to true in the body of the for loop, so the message "you lose!" can't ever be displayed.
Topic archived. No new replies allowed.