making is so the user can only type numbers

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

#include<iostream>
#include<cstdlib>
#include<ctime>


using namespace 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;
}



Please help
Last edited on
L28
use isdigit()
closed account (Dy7SLyTq)
@buffbill:
with getch?
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
Topic archived. No new replies allowed.