Hello there,
I am new to learning C and have been gradually working my way through the basic if statements, at present i'm stuck making the nesting If statement run the way I want in my program.
I have attempted to write a program where the user inputs their age and if the user's age is under 18 the program will print "You're too young!". And if the user is over the age of 18 the user can input their gender and a special message will print out determined by the gender they input.
The problem I have is when the program runs if skips the user option to input their gender and generate the special message.
Here is the code :
Code:
#include <stdio.h>
int main(int argc, char **argv)
{
int age;
char gender;
printf("How old are you?\n");
scanf( "%d",&age );
printf("Gender? (m/f)\n");
scanf( "%c", &gender);
if ( age >= 18 ) {
printf("Welcome");
if (gender == 'm')
{
printf( "guy");
}
if (gender == 'f')
{
printf( "gal");
}
}
if (age < 18)
{
printf("Too young");
}
return 0;
}
Any advice to where I am going wrong will be appreciated as I have tried hours and hours to find the problem!