I'm trying to build a program in C that:
- Gets age of user
- Checks if age is between 18 to 120
- Checks if age doesn't contain other characters such as letters, dots and so.
- If it isn't between 18-120 or contains other characters go back to section 1.
To check number 3 I believe that I need to scan the age from the user as a char but then i cant check if it's between 18 to 120. I can't use arrays or strings. This is the code that I have for now which checks that code doesn't contain other characters:
void main() {
char age;
int error = 0;
do
{
    error = 0;
    printf("Please enter your age:");
    scanf("%c", &name);
    while (name != '\n')
    {
        if ((name<'0') || (name>'9')){
            error++;
        }
        name = getchar();
    }
} while (error != 0);
}  
 
     
     
    