Needing help with this C++ problem. I get paid cash awards based on the value of
ID: 3630344 • Letter: N
Question
Needing help with this C++ problem.I get paid cash awards based on the value of the money recovered. I need to write a program that request the amount of the recovery as input and displays the award. I receive 10% of the first $75,000, 5% of the next $25,000, and 1% of the remainder, up to a maximum award of $50,000. Format the result to two decimal places. Program must compile in Microsoft Visual C++. Here is what I have so far.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int recovered, double payment;
if (recovered <= 75000)
payment = 0.1 * recovered;
else if (recovered <= 100000)
payment = 7500 + 0.05 * (recovered - 75000);
else if (recovered > 100000)
payment = 8750 + 0.01 * (recovered - 100000);
if (payment > 50000)
payment = 50000;
cout << fixed << showpoint;
Explanation / Answer
Okay, you've got most of the hard part of the program out of the way, I'd say. I didn't check the math, but you seem to have a handle on it and I'll let you figure that out.
So for the first part of the program, we need to request input and store it in the recovered variable. You could ask something like, "Enter the amount of money recovered: " or something along those lines.
Now that you have a stored value for the recovered variable, then you can do the comparison and set the payment variable accordingly, as you have done.
Then we need to display the payment on the screen.
Here's your program with the modifications:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int recovered;
double payment;
cout << "Enter the recovered amount: ";
cin >> recovered;
if (recovered <= 75000)
payment = 0.1 * recovered;
else if (recovered <= 100000)
payment = 7500 + 0.05 * (recovered - 75000);
else if (recovered > 100000)
payment = 8750 + 0.01 * (recovered - 100000);
if (payment > 50000)
payment = 50000;
cout << fixed << setprecision(2) << "The payment is: $" << payment << endl;
system("PAUSE");
return 0;
}
So, a few notes. First, because recovered and payment are different variable types, they have to be two different statements. Also, use the setprecision(2) to display the answer to 2 decimal places. Figure out if it rounds or truncates the number, and decide if that's what you want. Also, system("PAUSE"); at the end will pause the program so you can actually see what happens. Finally, is there anthing you could do to improve the program further? What about a loop that asks the user for another recovery amount each time? You could think about how you could implement that.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.