Next: The if-else Statement Up: The if statement Previous: Multiple Choice Questions

Exercises

In each of these exercises produce an algorithmic description before proceeding to write the program.

  1. Modify your solution to question 2 from Lesson 7 so that the message
    Trip too short for accurate results
    
    is printed if the mileage used to calculate the fuel consumption is less than 100 miles.

  2. Write a C++ program which when two integers x and y are input will output the absolute difference of the two integers. That is whichever one of (x-y) or (y-x) is positive. Think of all the cases that can arise and consequently plan a set of test data to confirm the correctness of your program.
  3. Percentage marks attained by a student in three exams are to be entered to a computer. An indication of Pass or Fail is given out after the three marks are entered. The criteria for passing are as follows:

    A student passes if all three examinations are passed. Additionally a student may pass if only one subject is failed and the overall average is greater than or equal to 50. The pass mark for an individual subject is 40.

    Write a C++ program to implement this task.



Next: The if-else Statement Up: The if statement Previous: Multiple Choice Questions