How can i make it where the user can only type numbers if they enter any symbol or letter the program goes awol please help asap using code blocks for a compiler
#include<iostream>
#include<cstdlib>
#include<ctime>
usingnamespace std;
int main()
{
bool goOn=true;
while(goOn)
{
srand(time(0));
int number=rand()%1000+1;;
int guess;
char answer;
cout << "Only enter numbers" << endl;
cout << "If you enter anything else the program goes awol" << endl;
cout << "It is not a bug but a feature" << endl;
cout<<"Im thinking of a number between 1-1000. Take a guess: ";
cin >> guess;
while(guess!=number)
{
if(guess>number)
{
cout<<"Too high, Guess again: ";
cin>>guess;
}
if(guess<number)
{
cout<<"Too low, Guess again: ";
cin>>guess;
}
}
if(guess==number)
{
cout<<"Congrats!! You got it.";
}
cout<<"would you like to play again?" << endl;
cout << "Enter y or n: ";
cin>>answer;
if(answer!='y')
{
goOn=false;
cout<<"thanks for playing!"<<endl;
}
}
return 0;
}
i have been messing with it for awhile i have had to teach my self everything and i am not learning very fast sadly hopefully i will get it to work soon