- Syntax :
if (condition1)
{
// block of code to be executed if condition1 is true }
else if (condition2)
{
// block of code to be executed if the condition1 is false and condition2 is true
}
else
{
// block of code to be executed if the condition1 is false and condition2 is false
}
- Program :
#include <iostream>
using namespace std;
int main() {
cout <<"\n----------------ELSE-IF STATEMENT----------------\n";
int a;
cout<<"\nEnter your age :";
cin>>a;
if (a <= 18) {
cout <<"\nYou are not eligible for applying for the job";
}
else if (a <= 45) {
cout <<"\nYou are eligible for applying for the job";
}
else {
cout << "\nYou are retired from the job";
}
return 0;
}
- Output :
No comments:
Post a Comment