I'm trying to code very simple code, and here it is:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int age;
char gender;
printf("How old are you? \n");
scanf("%d", &age);
printf("What is your gender? (m/f) \n");
scanf("%c", &gender);
if ((age >= 18 && gender == 'm')){
printf("You may enter this website ");
if (age <= 20)
{
printf("dude.");
}
}
if ((age >= 18 && gender == 'f')) {
printf("You may enter this website ");
if (age <= 20)
{
printf("young lady.");
}
}
else if (age < 18)
{
printf("Nothing to see here! \n");
}
return 0;
}
In the code above, I'm trying to use a nesting if
statement. But it doesn't work, not as I wish. After I enter the age, it prints out the sentence: What is your gender? (m/f).
When the second sentence is printed out, it terminates. But I don't know why. I want the user be able to enter the gender and based on the entered gender and age it should print out a sentence.
Could you please give me a hint?