C++ HELP NEEDED

Hi, Im fairly new at C++ and I need help with a C++ program. I have worked on the program all day since its due fairly soon. I can't seem to get this program written. Any help is appreciated!!!!

Here is the programming problem:

You have just purchased a stereo system that cost $1,000 on the following credit
plan: no down payment, an interest rate of 18% per year (1.5% per month), and
monthly payments of $50. The monthly payment of $50 is used to pay the interest,
and whatever is left is used to pay part of the remaining debt. Hence, the first
month you pay 1.5% of $1,000 in interest. That is $15 in interest. The remaining
$35 is deducted from your debt, which leaves you with a debt of $965.00. The
next month you pay interest of 1.5% of $965.00, which is $14.48. Hence, you can
deduct $35.52 (which is $50 - $14.48) from the amount you owe.
Write a program that will tell you how many months it will take you to pay off
the loan, as well as the total amount of interest paid over the life of the loan. Use a
loop to calculate the amount of interest and the size of the debt after each month.(Your final program need not output the monthly amount of interest paid and remaining debt, but you may want to write a preliminary version of the program that does output these values.) Use a variable to count the number of loop iterations and hence the number of months until the debt is zero. You may want to use other variables as well. The last payment may be less than $50 if the debt is small,but do not forget the interest. If you owe $50, then your monthly payment of $50 will not pay off your debt, although it will come close. One month's interest on
$50 is only 75 cents.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# include <iostream>

using namespace std;

int main()
{
    double loan_amount = 1000;
    double monthlyInterest = 1.5;
    double remainingDebt = 0.00;
    double interest;
    double monthlyPayment = 50.00
    int month = 1;

cout << "+-------+---------+-----------+-----------+" << endl;
cout << "| Month | Payment | Interest  | Remaining |" << endl;
cout << "+-------+---------+-----------+-----------+" << endl;

interest_rate = (loan_amount*(monthlyInterest/100));
loan_amount = loan_amountt+interest-payment;
Use a loop
You should have a closer look at while loops if you are having problems with this...
Also, make sure to keep attention to your code... it misses ';' in line 11, interest_rate is not defined(18), loan_amount with double t(19), so not defined eather. interest is not filled with any information when being used in (19) and payment (19) wasnt defined eather.

I would do it somewhat like this... (list style since it is must easier... do not want to mess with the correct display of the table):

1
2
3
4
5
6
7
# include <iostream>

using namespace std;

double calc_interest(double debtleft, double rate);
double calc_month_payment(double debtleft, double paymentrate);
int pay_debt(double debt, double paymentrate, double rt);


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
	double Debt;
	double PaymentPerMonth;
	double rate;

	cout << "Debt Payment Calculator v.1.0" << endl << endl;
	cout << "Please enter the debt you have to pay: ";
	cin >> Debt;
	cout << "How hig the rates per month are: ";
	cin >> PaymentPerMonth;
	cout << "How much interest you have to pay: ";
	cin >> rate;

	pay_debt(Debt, PayPerMonth, rate);
	return 0;
}


1
2
3
4
double calc_interest(double debtleft, double rate)
{
	return (debtleft / 100) * rate;
}


1
2
3
4
5
6
7
8
9
10
11
double calc_month_payment(double debtleft, double paymentrate)
{
	double interest = calc_interest(debtleft, 1.5);

	if (debtleft + interest < paymentrate)
	{
		return debtleft + interest;
	}
	else
		return paymentrate;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int pay_debt(double debt, double paymentrate, double rt)
{
	double Debt = debt;
	double interest_rate = rt;
	double payment;
	double total_interest = 0;

	int month = 0;
	double interest;

	while (Debt > 0)
	{
		month++;
		interest = calc_interest(Debt, interest_rate);
		payment = calc_month_payment(Debt, paymentrate);
		Debt = Debt - (payment - interest);

		/* You do not need those (as said in the task, 
		   but are usefull for checking if everything went smoothly

		cout << "Month:     " << month << endl;
		cout << "Payment:   " << payment << endl;
		cout << "Interest:  " << interest << endl;
		cout << "Remaining: " << Debt << endl << endl;

		*/

		total_interest = total_interest + interest;
	}

	cout << "\nIt will take you " << month << " months to pay the debt." << endl;
	cout << "Total interest to pay: " << total_interest << endl;
	system("pause");
	return month;
}


Make sure you understand the code... if you do not, ask questions.
Last edited on
Topic archived. No new replies allowed.