Ask the user their state of happiness on a scale of 1 to 10 and then gives a custom 2-line message based on their range, either 1-2, 3-4, 5-7, or 8-10. - C Language Basics

C examples for Language Basics:Hello World

Description

Ask the user their state of happiness on a scale of 1 to 10 and then gives a custom 2-line message based on their range, either 1-2, 3-4, 5-7, or 8-10.

Demo Code

#include <stdio.h>

int main()//w  w  w  .j  a  va 2  s .  c o m
{
    int prefer;
    printf("On a scale of 1 to 10, how happy are you?\n");
    scanf(" %d", &prefer);

    if (prefer >= 8)
    {
        printf("Great for you!\n");
    }
    else if (prefer >= 5)
    {
        printf("Better than average, right?\n");
    }
    else if (prefer >= 3)
    {
        printf("Sorry you're feeling not so great.\n");
    }
    else
    {
        printf("Hang in there--things have to improve, right?\n");
    }

    return 0;
}

Related Tutorials