Description
Using basic expressions, calculate and display values with input provided by the user.
In this exercise, we are simulating a credit card and how its various numbers are calculated
Requirements
- Add another #include line for <iomanip>. This additional line provides support for rounding and number precision.
#include <iostream> #include <iomanip>
- Declare a double called limit.
- Declare a double called balance
- Declare a double called usage
- Declare a double called trans
- Declare 2 doubles called new_bal, new_usage. Declare both of these variables on the same line
- Add this line of code after all your variable declarations. Type it exactly as below. This line of code is used for formatting numbers with decimal places.
cout << fixed << setprecision(1);
- Use cin to ask the user to enter a value for limit. See the Sample Interaction below on what message you will display to the user
- This is a good point to stop and do a test compile. If you run your program at this point, nothing will be displayed yet.
- After your test compile, fix any errors you may have encountered. Continue below once you fix any errors you had.
- Ask the user to enter a value for balance. See the Sample Interaction below on what message you will display to the user
- On one line, write an expression to calculate the utilization rate and store (assign) this value in usage. Utilization rate is simply the percentage of the balance against the limit.
usage = **write the expression here**
- Display a message with the calculated utilization rate (usage) expressed as a percentage. See Sample Interaction below.
- Ask the user to enter a value for trans. See the Sample Interaction below on what message you will display to the user
- Write an expression to calculate the new balance accounting for trans. Store the result of the calculation in new_bal
new_bal = balance + trans;
- Write an expression to calculate new_usage, similar to how you calculated new_bal above. Make sure to use the new balance against limit when calculating new_usage.
- Display the new balance and utilization rate (See Sample Interaction)
DO NOT USE
You may not use any conditional constructs such as the IF statement
Sample Interaction / Output
Enter credit card limit: 5000 Enter current balance: 2500 Your utilization rate is 50.0% How much is your new transaction? 350 Your new balance is $2850 Your utilization rate is now 57.0%
LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT
CATALOG ID: CPP-EXP0007
Print Requirements