Using the IF THEN ELSE IF THEN(nested IF) Construct
e.g A stadium has four stands A, B, C and D. The admission fee for stand A is $2.00, stand B is $2.50, stand C is $4.00 and stand D is $5.00. Read a stand and the number of spectators in the stand. Calculate and print the revenue for the stand. Begin Print “Enter a stand and the number of spectators” Read stand, spect If stand = “A” then Rev= spec * 2.00 Else If stand = “B” then Rev =spec * 2.50 Else If stand = “C” then Rev =spec * 4.00 Else If stand = “D” then Rev =spec * 5.00 Endif Endif Endif Endif Print “The stand Registered is” ,stand Print “The Revenue for the stand is $” ,rev:5:2 End.
Using IF THEN ELSE IF with logical operators AND/
OR. 1.Employees are given a salary increase as follows: - 6% of the salary if the salary is more than $3000.00 - 8% of the salary if the salary is more than $2000.00 but less than or equal to $3000.00 - 10% of the salary if the salary is less than or equal to $2000.00 Read a salary. Output the increase amount and the new salary. Begin Print “Enter a Salary” Read sal If sal > 3000 then Inc = sal * 6/100 Else If sal > 2000 And sal <= 3000 then Inc = sal * 8/100 Else If sal <= 2000 then Inc = sal * 10/100 Endif Endif Endif Newsal= sal + inc Print “The Increase Amount is”, inc Print “Your New Salary is”, newsal End. A student is given a 10% discount if the cost of a subject exceeds $100.00. 5% of the cost is refunded if the student receives grade “A” in the examination. Read the cost and a grade. Output the discount amount and the amount refunded. Begin Enter “cost and grade of the student” Read “cost, grade” If cost ≤ 100 then DAmount= 10/100 Else DAmount= 0/100 If grade= A then RAmount= 5/100 Else RAmount= 0/100 Endif Print “Discounted amount is”, DAmount, Print “Refunded amount is”, RAmount, End.