dimanche 2 octobre 2016

Basic If statement error

Hi there I am writing a basic code to tell the user whether or not they have received enough sleep. However no matter how many hours are entered it always displays the first message of "Sleep Deprived" even if theyve slept 10 hours.

   double hoursOfSleep;

printf("Please enter the amount of hours of sleep you received last night:\n");
scanf("%f", &hoursOfSleep);

if (hoursOfSleep <= 4){
    printf("Sleep deprived!\n");}

else if (hoursOfSleep <= 6){
    printf("You need more sleep.\n");}

else if (hoursOfSleep <= 8){
    printf("Not quite enough.\n");}

else printf("Well Done!\n");

Aucun commentaire:

Enregistrer un commentaire