Write a program that will tell you how many months it will take you to pay off t
ID: 3600583 • Letter: W
Question
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 Hierarchy Chart
a fully commented Program Listing
3 sample runs (one run uses the above example, one run with your data, one run with invalid loan, interest rate and amount paid)
a User’s 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
Explanation / Answer
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
double loan,rate,amt;
double intr,bal,rem;
cout << "Enter the amount of the loan: ";
cin >> loan;
cout << "Enter the yearly intrest rate: ";
cin >> rate;
cout << "Enter the monthly amount paid: ";
cin >> amt;
cout << setw(20)<< "Month" << setw(20)<< "Principle" << setw(20)<< "Intrest" << setw(20)<< "Principle" << setw(20)<< "Remaining" << endl;
cout << setw(20)<< " " << setw(20)<< "Paid" << setw(20)<< "Paid" << setw(20)<< "Balance" << setw(20)<< "" << endl;
for (int i = 0; loan > 0; i++){
intr = loan * (rate/1200);
bal = amt - intr;
rem = loan - bal;
cout << setw(20)<< i+1 << setw(20)<< fixed << setprecision(2) << loan << setw(20) << fixed << setprecision(2) << intr;
cout << setw(20)<< fixed << setprecision(2) << bal << setw(20)<< setprecision(2) << fixed << rem << endl;
loan = rem;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.