top of page
conditional else if  Sentence 

In this lesson we will explain how to make a sentenceelse if. Conditional statements simply set a condition. If the condition is met, the code will be executed. If the condition is not met, the code will not be executed. But if we want to put more than one condition, say, for example, three conditions, then we have to put a sentenceelse if twice.

if(){Code to check the first condition}
else if(){Code to check the second condition}
else if(){
Code to check the third condition }
else(){
Code that none of the previous conditions are met }

Project: Knowing the student’s final grade

We want to create a program to monitor the student's final grade
(Passing, Failing, Excellent, Very Good, Good, Acceptable)
Excellence from 90 to 100A
Very good from 80 to 89B
Good from 70 to 79C
Acceptable from 60 to 69D
Fail less than 60 F

#include<iostream>//We start by placing the libraries
using namespace std;//We start by placing the libraries
int main(){//main function
int Yourgrade;//We define a variable for the user score
cout<<"Enter your grade please";
cin>>Yourgrade;
if (Yourgrade>=90){//A If the score is more than or equal to 90, print 
cout<<"congratulation you got an A"<<endl;}
else if(Yourgrade>=80)​{//
BIf the score is more than or equal to 80, print 
cout<<"congratulation your grade is B"<<endl;}
else if(Yourgrade>=70)
​{//CIf the score is more than or equal to 70, print 
cout<<"you got C"<<endl;}
else if(Yourgrade>=60
)​{//C If the score is more than or equal to 60, print 
cout<<"You got D, study harder please"<<endl;}
else{cout<<"you fail, go play games and wait for next year and try your best";}
//
If the grade is not equal to any of the previous conditions, then you have unfortunately failed.
return 0;
}

image.png
bottom of page