Flow Control 1g

Description

The purpose of this challenge is to use the IF, NESTED-IF and IF-ELSE-IF statements to control program flow.

Requirements

  1. Declare a double variable called total. Initialize this to 0
  2. Declare an int variables called days_rented, start_miles, end_miles, extra_miles
  3. Declare a double variable called daily_rate. Initialize this to 100
  4. Declare double variables called unlimited_miles_cost, miles_surcharge
  5. Declare a char variable called cresponse
  6. Declare an int variable called days_late
  7. Declare a double variable called late_penalty
  8. Ask the user “How many days did you rent the car?”. Store their response in days_rented
  9. Ask the user “Are you returning the car late (y/n)?”. Store their response in cresponse
  10. If the user responds to returning the car late with a ‘y’
    1. Ask the user “How many extra days did you keep the car?” Store their response in days_late
    2. Calculate late_penalty by multiplying days_late by 75
  11. Otherwise, if the user responds to returning the car late with a ‘n’ then simply set late_penalty to 0
  12. Ask the user “Did you purchase the unlimited miles option (y/n)?” Store their response in cresponse
  13. If the user responds with a ‘y’ to unlimited miles, then
    1. Set miles_surcharge to 0
    2. Set unlimited_miles_cost to 45
  14. Otherwise, if the user responds with a ‘n’ to unlimited miles, then
    1. Set unlimited_miles_cost to 0
    2. Ask the user “What was the initial odometer reading?” Store their response in start_miles
    3. Ask the user “What was the final odometer reading?” Store their response in end_miles
    4. Calculate extra_miles as the difference between end_miles and start_miles
    5. Calculate miles_surcharge based on the following rates
      1. If extra_miles is less than 100, then each mile costs $0.50
      2. If extra_miles is more than 100 but less than or equal to 500, then each mile costs $0.43
      3. If extra_miles is more than 500 but less than or equal to 1000, then each mile costs $0.30
      4. Otherwise, if extra_miles exceeds 1000, then each mile costs 0.20
  15. Calculate total as the sum of
    1. The product of daily_rate and days_rented, plus
    2. unlimited_miles_cost, plus
    3. miles_surcharge, plus
    4. late_penalty
  16. Add #include <iomanip> under the first #include line at the top of the code.
  17. Write this code after the total calculation
    cout << fixed << setprecision(2) << endl;
    
  18. Look at the sample interaction below on how to display the final messages. Pay close attention to the line that displays Late Penalty. It displays NONE if there is no penalty. Otherwise, it displays a descriptive message and a calculation if there is a late penalty.
  19. Run the program a few times with varying inputs to really test it

Sample Interaction / Output

For how many days did you rent the car? 5
Are you returning the car late (y/n)? y
How many extra days did you keep the car? 2
Did you purchase the unlimited miles option (y/n)? y

Thank you for renting from Car++ Automobiles
Rental fee (5 days at $100/day): $500.00
Unlimited Miles charge: $45.00
Additional Miles charge: $0.00
Late penalty (2 days at $75/day): $150.00

Your final cost will be $695.00

RUN IT AGAIN:

For how many days did you rent the car? 5
Are you returning the car late (y/n)? n
Did you purchase the unlimited miles option (y/n)? n
What was the initial odometer reading? 1000
What was the final odometer reading? 3000

Thank you for renting from Car++ Automobiles
Rental fee (5 days at $100/day): $500.00
Unlimited Miles charge: $0.00
Additional Miles charge: $400.00
Late penalty: NONE

Your final cost will be $900.00

RUN IT AGAIN:

For how many days did you rent the car? 5
Are you returning the car late (y/n)? y
How many extra days did you keep the car? 2
Did you purchase the unlimited miles option (y/n)? n
What was the initial odometer reading? 2000
What was the final odometer reading? 2050

Thank you for renting from Car++ Automobiles
Rental fee (5 days at $100/day): $500.00
Unlimited Miles charge: $0.00
Additional Miles charge: $25.00
Late penalty (2 days at $75/day): $150.00

Your final cost will be $675.00
LEGEND
PROGRAM OUTPUT
USER ENTRY 
FROM INPUT 

CATALOG ID: CPP-FLOW0001G

Print Requirements