3.3.The else if statement
The else if used for more than two conditions and it’s must use between if and else statement.
Syntax 1:
if(condition) statement; else if(condition) statement; else if(condition) statement; else statement 1;
Syntax 2:
if(condition) { statement 1; ... statement n; } else if(condition) { statement 1; ... statement n; } else if(condition) { statement 1; ... statement n; } else { statement 1; ... statement n; }
Example 1:
#include<iostream.h> #include<conio.h> void main() { float score; cout<<"Enter Score: "; cin>>score; if(score<50) cout<<"Failed"; else if(score<85) cout<<"Very Good"; else cout<<"Excellent"; getch(); }