Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,095 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,631 people online right now. Registration is fast and FREE... Join Now!




loan program help

 
Reply to this topicStart new topic

loan program help, how to add the total interest paid

gee1288
3 Oct, 2007 - 06:09 PM
Post #1

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 2



Thanked: 1 times
My Contributions
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 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



#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;
}
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Loan Program Help
3 Oct, 2007 - 06:53 PM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
please use code tags when posting code - read the grey text on the background of the reply text box.

you probably want to use a while statement rather than a for statement - the current syntax you're using in the for loop is essentially a hack that makes it behave like while loop. the following shows a reasonable syntax for the loop you are trying to perform:

month=0;
while (loan>0) {
month++;
//the rest of your loop code
}

the rest of your loop body appears to be fine, except that you're not calculating the total interest paid properly - but i'll leave that for you to look over.

hope that helps,

-jjh
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:31PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month