Aloha All!
I had completed the assignment stated in the title, however, I’m experiencing a weird issue with it going into an infinite loop whenever a char is entered. Anyone have any ideas?
Thanks!
#include <iostream>
using namespace std;
/*
GAME RULES:
1) P1 selects random #
2) P2 guesses #
3) Game will tell P2 if guess is too high or low
4) The game will keep track of guess attempts by P2
*/
int main()
{
int rndnum {};
int guess {};
int counter {};
cout << "Enter random # from 1-99: ";
cin >> rndnum;
while (rndnum >= 100 || rndnum <= 0)
{
cout << "Please make sure # is from 1-99: ";
cin >> rndnum;
}
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThe random # is in!\nNow guess that #\n(Hint: it's btwn 1-99): ";
cin >> guess;
counter++;
while (guess != rndnum)
{
if (guess > rndnum)
{
cout << "You thought wrong buddy!\nGuess is higher than selected #\nTotal guess count: " << counter << '\n';
cout << "Guess again: ";
cin >> guess;
counter++;
}
else
{
cout << "You thought wrong buddy!\nGuess is lower than selected #\nTotal guess count: " << counter << '\n';
cout << "Guess again: ";
cin >> guess;
counter++;
}
}
if (guess == rndnum)
{
cout << "You are a weener!!! Cungratz!\nTotal guess count: " << counter << endl;
}
return 0;
}