|
Hey guys im currently working on an assignment that does a loan calculation. Ive got 3 problems when i run the program the months start at zero i want it to start at 1 but when i make month=1 the total months become 25 i just want it to start from 1. Two i want to add the total interest paid which is the variable sumtin. i want to get the total instead of showing the last interest paid on the last month.Three when i run the program theres two places where it shows a before loan and after loan. i cant seem to show the first loan before calculations it does the calculations right away. anyway heres my code so far its does what i want it to do but output is what i cant figure out
heres the assignment question and my code.
PROBLEM:
You are to write a program to tell you how many months it will take to pay off a loan, as well as the total amount of interest paid over the life of the loan.
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.
You are to hand in: a Title page a Top Down Development (P0, P1, P2 etc.) pseudocode a fully commented Program Listing 2 sample runs (one run uses the above example) a Users Guide (showing Purpose, Sample Input, Sample Output, Assumptions/Limitations)
A sample session may run as follows: Enter the amount of the loan 1000.00 Enter the yearly interest rate 18.0 Enter the monthly amount paid 50.00
Month Principle Interest Principle Remaining Paid Paid Balance 1 1000.00 15.00 35.00 965.00 2 965.00 14.48 35.52 929.48 3 929.48 13.94 36.06 893.42 . . 24 41.12 0.71 49.29 -2.17
Number of months to pay of the loan: 24 Total interest paid on loan: 197.83 You have a credit of: -2.17
#include <iostream> #include <iomanip> using namespace std;
int main() { double loan,yrint,mptpd,sumtin; double decint,prince,totalprnce; int month; cout << "Enter the amount of loan: "; cin >> loan; cout << "Enter the yearly interest: "; cin >> yrint; cout << "Enter the monthly amount paid: "; cin >> mptpd; cout << endl; cout << "Month"; cout << setw(20) << "Princpal Interest"; cout << setw(10) << "Paid"; cout << setw(20) << "Principal Paid"; cout << setw(20) << "Remaining Balance" << endl; for (month=0;loan>0;month++) { decint = yrint/100/12; sumtin = loan*decint; prince = mptpd - sumtin; loan = loan - prince;
cout << fixed << showpoint << setprecision(2); cout << setw(4) <<month; cout << setw(17) << loan; cout << setw(15) << sumtin; cout << setw(15) << prince; cout << setw(20) << loan; cout << endl; } cout << "The total months you need to pay off is " << month << endl; cout << "Total interest paid on loan " << prince << endl; cout << "You have a credit of " << loan << endl;
return 0; }
|