# C++ Unable to

February 22, 2011 at 04:26:03
Specs: Windows Vista
 I am using the “if else” and variable count for loop iterations which needs to result in zero balance. I have written my code for the following problem but, I cannot get the final results. Which is the final balance should show a zero balance. I would like to know how to fix it.Please see problem and code below.Thank You in Advance.PROBLEMYou have just purchased a stereo system that costs \$2,000 on the following credit plan: no down payment, an interest rate of 18% per year (and hence 1.5% per month) and monthly payments of \$75.The monthly payment of \$75 is used to pay the interest and whatever is left over is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of \$2,000 in interest . That’s \$30 in interest. So, the remaining \$45 is deducted from your debt, which leaves you with a debt of \$1955.00.The next month you pay interest of 1.5% of \$1955.00, which is \$29.32 and you deduct \$75 - \$29.32 which is \$45.67 from the amount you owe.Have your program print out the month, the amount of interest paid, and the amount of the debt that is paid and the debt that remains in a nice table form.Make sure to include a line in the table for the final month that you pay.Your remaining debt should be zero for that line! Be sure to print money out to 2 decimal places, as shown below.Sample output: Thank you for purchasing your new stereo system.The following is your payment plan for the cost of \$2000.00with 1.50% interest and payments of \$75.00 a month.Month Interest Paid Debt Paid Total Payment Balance1 30.00 45.00 75.00 1955.002 29.32 45.67 75.00 1909.333 28.64 46.36 75.00 1862.964 27.94 47.06 75.00 1815.915 27.24 47.76 75.00 1768.156 26.52 48.48 75.00 1719.677 25.80 49.20 75.00 1670.478 25.06 49.94 75.00 1620.529 24.31 50.69 75.00 1569.8310 23.55 51.45 75.00 1518.3811 22.78 52.22 75.00 1466.1512 21.99 53.01 75.00 1413.1513 21.20 53.80 75.00 1359.3414 20.39 54.61 75.00 1304.7315 19.57 55.43 75.00 1249.3016 18.74 56.26 75.00 1193.0417 17.90 57.10 75.00 1135.9418 17.04 57.96 75.00 1077.9819 16.17 58.83 75.00 1019.1520 15.29 59.71 75.00 959.4321 14.39 60.61 75.00 898.8322 13.48 61.52 75.00 837.3123 12.56 62.44 75.00 774.8724 11.62 63.38 75.00 711.4925 10.67 64.33 75.00 647.1626 9.71 65.29 75.00 581.8727 8.73 66.27 75.00 515.6028 7.73 67.27 75.00 448.3329 6.73 68.27 75.00 380.0630 5.70 69.30 75.00 310.7631 4.66 70.34 75.00 240.4232 3.61 71.39 75.00 169.0333 2.54 72.46 75.00 96.5634 1.45 73.55 75.00 23.0135 0.35 23.01 23.36 0.00Note that the last payment is \$23.36,Hints: Use a variable to count the number of loop iterations and hence the number of months until the debt is zero. Be careful, the last payment may be less than \$75. Also, don’t forget the interest on the last payment. If you owe \$75,then your monthly payment of \$75 will not pay it off, but will come close.Make sure you look carefully at your final output to check that it is correct!#include#includeusing namespace std;int main(){ float balance; float interest; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); double loan, monthlypay, IntRat; double e = 0; double a, b, c, d; double Interestpay; double i; cout << "Enter the amount of the loan: \$"; cin >> loan; cout << "Enter the interst per year:"; cin >> Interestpay; cout << "Enter the monthly pay: \$"; cin >> monthlypay; c = loan; cout << endl; cout << endl; cout << endl; for ( i=1; c>0; i++) { IntRat = Interestpay/100/12; a = IntRat*c; b = monthlypay-a; cout << "Month: "<=b) c = c -b; else if (c>0.1) c=c*1; c = 0; cout << "Your last payment is " << c << endl; cout << "\nThe total month is:" <

See More: C++ Unable to

#1
February 22, 2011 at 18:15:50
 double a, b, c, d;Don't do this. Especially if you expect other people to read your code.That said, I'd run my for loop until monthlypay was >= the remaining principle + the interest. Then, after the loop, I'd compute the final balance.How To Ask Questions The Smart Way

Report •

#2
February 22, 2011 at 18:39:32
 Thank you for the help.

Report •

Related Solutions