### Isdigit for checking number/letter

I'm doing a program that when letter/s is/are entered the program will not acknowledge it and it will say:
 `` `` ``"You're so stupid! You didn't answer my question correctly!"``

But when I entered number/s it shows the same statement. I know there's something wrong with this, I've tried everything I could but I can't figure it out. My code doesn't seem to work. I did research about this but I don't get it. Can someone explain to me?
Here's my code so far:

 ``1234567891011121314151617181920212223242526272829`` ``````#include #include using namespace std; int main () { int age=0; cout<<"Enter age: "; cin>>age; if (isdigit(age)){ if (isdigit(age<=17)) { cout<<"You're not allowed here! You're too young"; } else if (isdigit(age>=18 || age<=30)) { cout<<"You're what we've been looking for!"; } else if (isdigit(age>=31 || age<=100)) { cout<<"You're too old for this!"; } else if (isdigit(age>=101)) { cout<<"Impossible!"; } } else { cout<<"You're so stupid! You didn't answer my question correctly!"; return 0; } } ``````

Thanks a lot!
Last edited on
Firstly digits are 0-9 ( lines 11-20 ). Secondly isdigit function is used on characters. So You're going to have to make line 6 a string and use std::getline. Then you should check the string to see if every character is a digit if they are not all digits then set a new variable to 'n' or something if a character variable otherwise if it's a boolean set it to false. If they are all digits then assign the value to an integer. Now use if statements to 1) check if they are all digits using the above variable. Then 2) If they are all digits then 2 do the age check using the integer value.
Topic archived. No new replies allowed.