Decision Statements 89
printf ("rtTotal Sales : %.2f”,sale);
printf (" iBasic Salary: %.2f',bs);
printf ("
Hra : %.2f',hra);
printf ("nDa : %.2f',da);
printf ("nConveyance : %.2f',cv);
printf ("nlncentive : %.2f',incentive);
printf ("nBonus ; %.2f'/bonus);
printf ("nGross Salary : %.2f',ts);
getchO;
i
OUTPUT : Enter Total Sales in Rs.: 100000
Total Sales
Basic Salary
Hra
Da
Conveyance
Incentive
Bonus
Gross Salary
100000.00
3000.00
600.00
3300.00
500.00
10000.00
500.00
17900.00
Explanation This program calculates the salary of a medical representative depending on sales.
H>e Basic salary is same but other allowances and incentive changes depends on sales. If sale is
more than 100000 rate of allowances and incentive are as per table (1) otherwise table (2). The i f
condition checks the given figure of sales. If sale is larger than Rs.100000 first block following i f
statement is executed otherwise
else block is executed. In both the blocks simple arithmetic
operations are performed to calculate the allowances and total salary.
5.4 NESTED i f -else STATEMENT
In this kind of statements number of logical conditions are checked for executing various statements.
Here, if any logical condition is true the compiler executes the block followed by i f condition
otherwise it skips and executes else block. In i f . . else statement else block is executed by
default after failure of condition. In order to execute the e ls e block depending upon certain condition
we can add repetitively i f statements in else block. This kind of nesting will be unlimited.
The syntax of the i f . . e ls e . . i f ladder is as follows.
Syntax of if - else ..if statement can be given as follows.
if ( condition)
statement 1;
statement 2;
if block