Note: I've tried using an if statement with break as part of the while loop code, but that did not change the output.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int month = 1;
double balance = 1000, interest, debt, payment;
cout << "This program shows you how many months it will take\n";
cout << "to pay off a $1,000 debt, when paying $50 a month and\n";
cout << "with an interest rate of 18% per year or 1.5% per month.\n";
cout << "No down payment was required to get the credit plan.\n";
cout << "\n";
cout << "\t\tMonth\tInterest Paid\tDebt Paid\tBalance \n";
do
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
payment = 50;
interest = balance * 0.015;
debt = payment - interest;
balance = balance - (payment - (balance * 0.015));
cout << "\t\t" << month << "\t $" << interest << "\t\t $" << debt << "\t\t $" << fabs (balance) << endl;
month++;
} while (balance > 50);
while (balance > 0)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
interest = balance * 0.015;
payment = balance + interest;
debt = payment - interest;
balance = balance - (payment - (balance * 0.015));
cout << "\t\t" << month << "\t $" << interest << "\t\t $" << debt << "\t\t $" << balance << endl;
month++;
}
char letter;
cout << "Enter letter to end:\n";
cin >> letter;
return 0;
}
The current output:
Month Interest Paid Debt Paid Balance 1 15.00 35.00 965.00 2 14.47 35.52 929.48 3 13.94 36.06 893.42 4 13.40 36.60 856.82 5 12.85 37.15 819.67 6 12.30 37.70 781.97 7 11.73 38.27 743.70 8 11.16 38.84 704.85 9 10.57 39.43 665.42 10 9.98 40.02 625.40 11 9.38 40.62 584.79 12 8.77 41.23 543.56 13 8.15 41.85 501.71 14 7.53 42.47 459.24 15 6.89 43.11 416.13 16 6.24 43.76 372.37 17 5.59 44.41 327.95 18 4.92 45.08 282.87 19 4.24 45.76 237.11 20 3.56 46.44 190.67 21 2.86 47.14 143.53 22 2.15 47.85 95.68 23 1.44 48.56 47.12 24 0.71 47.12 0.00 25 0.00 0.00 -0.00
This post has been edited by Sunny04: 03 October 2009 - 06:25 PM

New Topic/Question
Reply




MultiQuote




|