C Programming Tutorial – 14 – if – else if :

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

float agrade,bgrade,cgrade;
printf(“Please enter you 3 grades. \n”);
scanf(” %f”, &agrade); // You should not use \n in scanf. !!!!
scanf(” %f”, &bgrade);
scanf(” %f”, &cgrade);
float averagegarde = (agrade+bgrade+cgrade)/3;
printf(“Your average grade is : %.2f \n”,averagegarde);
if (averagegarde>=90){ // Use of else if
printf(“Your FINAL grade is A. \n”);
} else if (averagegarde>= 80) {
printf(“Your FINAL grade is B. \n”);
} else if (averagegarde>= 70){
printf(“Your FINAL grade is C. \n”);
} else {
printf(“You could not pass the course ! \n”);
}
if ((agrade>=90) && (bgrade>=80) && (cgrade>=70)){       // In this part we compare more 1 values and use logic syntax like && ||
printf(“You can enter to Final EXAM.\n”);
} else
{
printf(“You cannot enter to Final exam !\n”);}

return 0;

}