Description
The purpose of this challenge is to use the IF, NESTED-IF and IF-ELSE-IF statements to control program flow.
Requirements
- Declare a double variable called total. Initialize this to 0
- Declare an int variables called days_rented, start_miles, end_miles, extra_miles
- Declare a double variable called daily_rate. Initialize this to 100
- Declare double variables called unlimited_miles_cost, miles_surcharge
- Declare a char variable called cresponse
- Declare an int variable called days_late
- Declare a double variable called late_penalty
- Ask the user “How many days did you rent the car?”. Store their response in days_rented
- Ask the user “Are you returning the car late (y/n)?”. Store their response in cresponse
- If the user responds to returning the car late with a ‘y’
- Ask the user “How many extra days did you keep the car?” Store their response in days_late
- Calculate late_penalty by multiplying days_late by 75
- Otherwise, if the user responds to returning the car late with a ‘n’ then simply set late_penalty to 0
- Ask the user “Did you purchase the unlimited miles option (y/n)?” Store their response in cresponse
- If the user responds with a ‘y’ to unlimited miles, then
- Set miles_surcharge to 0
- Set unlimited_miles_cost to 45
- Otherwise, if the user responds with a ‘n’ to unlimited miles, then
- Set unlimited_miles_cost to 0
- Ask the user “What was the initial odometer reading?” Store their response in start_miles
- Ask the user “What was the final odometer reading?” Store their response in end_miles
- Calculate extra_miles as the difference between end_miles and start_miles
- Calculate miles_surcharge based on the following rates
- If extra_miles is less than 100, then each mile costs $0.50
- If extra_miles is more than 100 but less than or equal to 500, then each mile costs $0.43
- If extra_miles is more than 500 but less than or equal to 1000, then each mile costs $0.30
- Otherwise, if extra_miles exceeds 1000, then each mile costs 0.20
- Calculate total as the sum of
- The product of daily_rate and days_rented, plus
- unlimited_miles_cost, plus
- miles_surcharge, plus
- late_penalty
- Add #include <iomanip> under the first #include line at the top of the code.
- Write this code after the total calculation
cout << fixed << setprecision(2) << endl;
- 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.
- 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