this is the problem:
You have just purchased a stereo system that costs $1000 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 $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 $1000 in interest. That is $15 in interest. So, 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. Put out the monthly amount of interest paid and remaining debt. 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.
#include <iostream>
usingnamespace std;
int main()
{
char x;
double total_int_paid, pay_duration, total_months, remaining_debt, cost=1000;
int c=0; //c is the count down of months
constint monthly_pay=50;
constdouble monthly_interest=.015;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"You brought a stereo system that is $1000 with a 1.5% interest per month and \n";
cout<<"monthly payments of $50\n";
cout<<"stereo system is $1000\n"<<"monthly interest is 1.5%\n"<<"monthly payment is $50\n";
while (remaining_debt<50)
{
remaining_debt=cost-(monthly_pay-(cost*monthly_interest));
c++;
}
cout<<remaining_debt<<endl;
cout<<c;
cin>>x;
return 0;
}
i didn't finish yet because my while loop isn't working. i want the loop to keep looping until the remaining debt is less than 50 but it just does 1 loop. i also want to count how many loops i did and c is the counter. when i run it, it gives me 965.00 for the remaining debt and 1 for the c(how many times it looped).
how do i fix this?
i want the loop to keep looping until the remaining debt is less than 50 but it just does 1 loop.
`while(remaining_debt < 50)' will keep running while remaining_debt is below 50, meaning if you set remaining_debt to more than 50 it will jump out of the loop which seems the opposite of what you want. See if this does what you want:
#include <iostream>
usingnamespace std;
int main()
{
char x;
double total_int_paid, pay_duration, total_months, remaining_debt, cost=1000;
int c=0; //c is the count down of months
constint monthly_pay=50;
constdouble monthly_interest=.015;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"You brought a stereo system that is $1000 with a 1.5% interest per month and \n";
cout<<"monthly payments of $50\n";
cout<<"stereo system is $1000\n"<<"monthly interest is 1.5%\n"<<"monthly payment is $50\n";
remaining_debt = cost; // starting debt is full price of stereo
while (remaining_debt>50)
{
remaining_debt -= monthly_pay - (remaining_debt*monthly_interest); // subtract monthly payment, add interest
c++;
}
cout<<remaining_debt<<endl;
cout<<c;
cin>>x;
return 0;
}