if-else-if Statement in C
For Complete YouTube Video: Click Here
In this class, we will try to understand the if-else-if Statement in C.
We have already discussed if-else and nested if-else statements in C.
Table of Contents
if-else-if Statement
Here we have to understand the else-if statement.
Else-if is a keyword used whenever we need to compare a series of statements and make the decisions, then else-if is used.
Example for if-else-if Statements
Let us try to understand the use of else-if with a real-world example.
The image below is the details provided by an insurance company.
The above details are policy worth and the commissions provided to the insurance agents.
Now we have to write the program for the insurance company to pay the monthly salary.
The above table based upon the policies worth made by the agents, the commissions are mentioned.
Those commissions are to be added to the base salary of 15000.
Now we have to compare a series of options and make the decisions.
For such kind of implementations, we can use if-else-if statement in C.
The image below is the program for the above requirement.
In the above program using else-if, we are comparing multiple options.
The basic salary of the insurance agent is 15000/- and to that the commission has to added.
If any statement is true, then the body of that if-else-if statement will be executed, and we will come out of the entire if statement.
If none of the else-if statement is true, then else will get executed.
In our case, we will be print “No Salary”.