Skip to main content

//If-Else-If Example:- Grade

 //if-else-if Example:- Grade



CODE

👇

  1. #include<iostream>
  2. using namespace std;
  3. int main() //Main Function
  4. {
  5. int sub1 = 81;
  6. int sub2 = 79;
  7. int sub3 = 87;
  8. int sub4 = 83;//int use for integer value.
  9. int sub5 = 85;
  10. int per;
  11. int per2;

  12. per = sub1 + sub2 + sub3 + sub4 + sub5;
  13. per2 = per / 5;
  14. cout<<"Persentage:"<<per2<<endl;

  15. if(per2 >= 90)
  16. {
  17. cout<<"Grade A"<<endl; //These statements would execute if the condition is true
  18. }

  19. else if(per2 >= 80)
  20. {
  21. cout<<"Grade B"<<endl; //'cout' use for print line 
  22. }

  23. else if(per2 >= 70)
  24.         {
  25.         cout<<"Grade C"<<endl; //"endl" use for linebreak. 
  26.         }

  27. else if (per2 >= 60)
  28.         {
  29.         cout<<"Grade D"<<endl;
  30.         }

  31. else if (per2 >= 40)
  32.         {
  33.         cout<<"Grade E"<<endl;
  34.         }

  35. else
  36. {
  37. cout<<"Grade F"<<endl; //These statements would execute if all the conditions return false.
  38. }
  39. return 0; //Return Statement
  40. }


👉Execute👈


//Output

/*

Persentage:83

Grade B

*/



                                            //ThE ProFessoR