I'm trying to make a simple number guessing program with while loop but even after finding the right number (I changed the num with 5 and it didn't work) it does not exit the while loop. Can you tell me where the problem is?
int guess;
int num;
cout << "Enter the number (0-10): ";
cin >> guess;
while(guess != num){
int num = rand()%10;
cout << "Nope, keep trying." << endl;
cout << "Enter the number (0-10): ";
cin >> guess;
}
cout << "Congrats, you've found the number!" << endl;
Aucun commentaire:
Enregistrer un commentaire