Problem In C++!!!

targetblimp

Disciple
how do i enter a datatype check in turbo c++.Suppose i've to enter my age and i accidently(or intently) enter a character, how i am supposed to make the program reenter my age using ASCII code.

this one's probably easy for you guys but it really got me cracked considering i am a noob in C++:S :ashamed:
 
check if the value entered ranges between 48 - 57

ascii of 0 - 48

ascii of 9 - 57

get the user's input and check if it ranges within this
 
Dude... Even if u dunno the ASCII value, then also, u can code it this way...

char c;

while(c!='\n'){

c=getch();

if(c<'0' || c>'9')

printf("\n Enter digits only");

//code u need

//

//

}
 
Lol datatype check between int and char..well char is a type of int only.

IF u want to repeat the steps if a wrong choice like alphabet is entered, use a do-while loop or use a goto command with a condition

KingKrool said:
isnum, isalpha, isalnum

Three functions that help you do what you need.

Yeah..just include ctype.h
 
Back
Top