ifscore.c

#include <stdio.h>

int main()
{
   int score;
   printf("Input score: "); scanf("%d", &score);
   if ((score < 0) || (score > 100))
       printf("Invalid score input!\n");
   else
   {
      if (score >= 90) printf("Grade = A\n");
         else if (score >= 80) printf("Grade = B\n");
            else if (score >= 70) printf("Grade = C\n");
               else if (score >= 60) printf("Grade = D\n");
                  else printf("Grade = F\n");
   }
   return 0;
}
  • This is an example of a nested with compound conditions to determine the grade from the score.
  • Question: Why don't we put a stronger form of an if? Suppose like to determine grade A. It should be within the range of 90 to 100. Why don't we put the condition like this: if ((score >= 90) && (score <=100)) ?

 


Where to go

Chapter 2
News Page
Lesson 1 contents
Contacting Me


Roby Joehanes © 2001

Hosted by www.Geocities.ws

1