Home > Back-end >  New turn post
New turn post

Time:12-06

Turn to
My cousin asked me early in the United States a C language problem,
First show "input age", the user will enter the Numbers, if the input is not number, pop-up prompt from "enter the Numbers", until the user input number, just according to age,
Now can only judge the input is output, digital and success but judgment is not for the digital input, and circulation tips how to writing conditions,
Is I too food, also please bosses give directions
# include & lt; Stdio. H>

Int main ()
{
char ch;
Printf (" Input your age \ n ");
The scanf (" % c ", & amp; Ch);
If (ch>='0' & amp; & Ch<='99')
{
Printf (" correct \ n ");
Printf (" your age is % d ", ch);
return 0;
}
If (-- -- -- -- -- -)
Printf (" error "\ n");
Printf (" both Please input your age again ");

return 0;
}

CodePudding user response:

Can't use char, it can only receive one character at a time, to receive with int, then a cycle

CodePudding user response:

Available ASCII table determine whether to digital, then will be converted to digital characters

CodePudding user response:

The while loop

CodePudding user response:

Did some modification on your code, reference
 
# include & lt; Stdio. H>
# include & lt; String. H>

Int main ()
{
Char ch [8]={0};

Printf (" Input your age \ n ");
The scanf (" % s ", ch);
int i=0;
While (ch [I]!='\ 0')
{
If (ch [I] & gt;='0' & amp; & Ch [I] <='9')
{
I++;
}
The else
{
Printf (" error "\ n");
Printf (" both Please input your age again \ n ");
return 0;
}
}

Printf (" correct \ n ");
Printf (" your age is % s ", ch);

return 0;
}
  • Related