[source code] C Programming Tutorial - 18 - Nesting if Statements

+3 Bucky Roberts · August 4, 2014



#include <stdio.h>
#include <stdlib.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){
        printf("You may enter this website ");

        if(gender == 'm'){
            printf("dude");
        }
        if(gender == 'f'){
            printf("m'lady");
        }
    }

    if(age < 18){
        printf("Nothing to see here");
    }

    return 0;
}


Post a Reply

Replies

Oldest  Newest  Rating
0 Borat Sagdiyev · August 11, 2014
He hasn't gone over 'else' yet.
  • 1

C

107,254 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator