Next: Exercises Up: Nested if and if-else Previous: Multiple Choice Questions

Review Questions

  1. It is decided to base the fine for speeding in a built up area as follows - 50 pounds if speed is between 31 and 40 mph, 75 pounds if the speed is between 41 and 50 mph and 100 pounds if he speed is above 50 mph. A programmer writing a program to automate the assessment of fines produces the following statement:
    if (speed > 30)
       fine = 50;
    else if (speed > 40)
       fine = 75;
    else if (speed > 50)
       fine = 100;
    
    Is this correct? What fine would it assign to a speed of 60 mph? If incorrect how should it be written?

  2. Write a nested if-else statement that will assign a character grade to a percentage mark as follows - 70 or over A, 60-69 B, 50-59 C, 40-49 D, 30-39 E, less than 30 F.



Next: Exercises Up: Nested if and if-else Previous: Multiple Choice Questions