If else statements in c programming.

#include <stdio.h>

int main()
{
    // Declare a variable to store the user's age
    int age;

    // Prompt the user to enter their age
    printf("Please enter your age: \n");

    // Read the input age from the user
    scanf("%d", &age);

    // Check if the age is less than 18
    if (age < 18)
    {
        // If age is less than 18, inform the user that they are too young to play the game
        printf("Sorry, you are too young to play this game.\n");
    }
    // Check if age is greater than or equal to 18 and less than or equal to 60
    else if (age >= 18 && age <= 60)
    {
        // If age is within the specified range, tell the user they can play the game
        printf("You are eligible to play this game. Have fun!\n");
    }
    // If age is not less than 18 or within the range of 18 to 60, it must be greater than 60
    else
    {
        // In this case, let the user know that they are too old to play the game
        printf("Sorry, you are too old to play this game.\n");
    }

    return 0;
}

Comments

Popular posts from this blog

Weird Algorithm || Introductory Problem || CSES