Hello,
So I've just started C and have been following thenewboston's tutorials.
Here, when I enter a letter for the age input, it counts it as a really high number. For example, if it put 'f':
I also noticed it doesn't let me proceed to the next user input which is the gender. Can anyone explain this and suggest a fix?
Thanks.
So I've just started C and have been following thenewboston's tutorials.
PHP Code
<?php
#include <stdio.h>
int main(void){
int age;
char gender;
printf("What is your age?:\n");
scanf(" %d", &age);
if (age >= 18){
printf("You are allowed to access this website since you are %d years old, enjoy!\n", age);
printf("What is your gender? (m/f):\n");
scanf(" %c", &gender);
if (gender == 'm' || gender == 'M'){
printf("You're a male.");
}
}
else if (age < 18){
printf("You are not allowed to access this website since you are %d years old :(", age);
}
else{
printf("Something went wrong!");
}
}
PHP Code
<?php
You are allowed to access this website since you are 4194432 years old, enjoy!
What is your gender? (m/f):
Press any key to continue . . .
Thanks.


