This says it is producing an infinite loop, but i cant find where
#include <iostream>
using namespace std;
int main ()
#include <cstdlib>
{
char y = 'y';
char n = 'n';
char LikeToPlay;
int Guess;
cout << "Would you like to play? (enter y or n)" << endl;
cin >> LikeToPlay;
while (LikeToPlay == y)
{
int RandomNumber;
srand (99);
RandomNumber = rand() % 10 + 1;
cout << "Enter your guess" << endl;
cin >> Guess;
if (Guess > RandomNumber){
cout << "Your guess is greater than the random number." << endl; }
else if (Guess < RandomNumber){
cout << "Your guess is less than the random number." << endl; }
else if (Guess == RandomNumber){
cout << "Congratulations. You guessed correctly." << endl;
cout << "Would you like to play again? (enter y or n)" << endl;
cin.ignore();
cin >> LikeToPlay;
}
}
if (LikeToPlay != y)
{cout << "Thanks for playing. Come back again." << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main ()
#include <cstdlib>
{
char y = 'y';
char n = 'n';
char LikeToPlay;
int Guess;
cout << "Would you like to play? (enter y or n)" << endl;
cin >> LikeToPlay;
while (LikeToPlay == y)
{
int RandomNumber;
srand (99);
RandomNumber = rand() % 10 + 1;
cout << "Enter your guess" << endl;
cin >> Guess;
if (Guess > RandomNumber){
cout << "Your guess is greater than the random number." << endl; }
else if (Guess < RandomNumber){
cout << "Your guess is less than the random number." << endl; }
else if (Guess == RandomNumber){
cout << "Congratulations. You guessed correctly." << endl;
cout << "Would you like to play again? (enter y or n)" << endl;
cin.ignore();
cin >> LikeToPlay;
}
}
if (LikeToPlay != y)
{cout << "Thanks for playing. Come back again." << endl;
}
return 0;
}