Here is my code so far for my program:
#include<iostream>
using namespace std;
int main()
{
int number;
int guess;
char reply;
srand (time(NULL));
number = rand() % 1000 + 1;
do
{
do
{
cout << "Guess the Number" << endl;
cin >> guess;
if (guess > number)
{
cout << "Too High" << endl;
}
else if (guess < number)
{
cout << "Too Low" << endl;
}
else if (guess == number)
{
cout << "Correct" << endl;
}
else
{
cout << "Invalid Input" << endl;
}
} while (guess != number);
cout << "Would you like to play again? <Y/N>" << endl;
cin >> reply;
} while (reply == 'y' || reply == 'Y');
}
My problem is that when I input a word or something besides a number for the guess, the program runs the code thousands of times and glitches out. I want to make it like:
if (guess != "a number") then it outputs something and you can continue to guess.
I've not been doing c++ very long and am a beginner and would like some help.
Thank you.