vendredi 3 mars 2017

Can i write this in a different way?

I don't want to use the if-statement chain. Can i write the code in a different way? I want to use the smallest amount of if-statement.

#include <stdio.h>
#include <stdlib.h>
main()
{
    int temp;

    printf("type a number: "),
    scanf("%d", &temp);
    printf("\n\n");

    if (temp == 18)
    {
        printf("The temperature is normal, stable conditions. \n");
    }
    else if (temp < 5)
    {
        printf("The temperature is too cold. Massive damage. \n");
    }
    else if (temp > 25)
    {
        printf("The temperature is too hot. Massive damage. \n")
    }

    else
    {
        printf("The temperature is unstable. This condition can make damages. \n");
    }
    system("PAUSE");
}

Aucun commentaire:

Enregistrer un commentaire