-
October 5th, 2009, 12:31 PM
#1
Help Please: Comparing loans w/ various interest rates
Alright, I am new to C++, and thought I would get a book and start learning it. I was doing some of the practice exercises at the end of the chapter, and I am stumped.
I have to let the user enter a loan amount and loan period in number of years and display the monthly and total payments for each interest rate starting from 5% to 8%, with an increment of 1/8.
Example of the Output:
Loan Amount: 1000
Number of Years: 5
Interest rate Monthly Payment Total Payment
5% 188.71 11322.74
5.125% 189.28 11357.13
etc...
I have got the basics, and I know I need to use a loop, but I am pretty lost. If someone could point me in the right direction I would appreciate it.
What I currently have
#include <iostream>
using namespace std;
int main()
{
cout << "Loan Amount:";
double loan;
cin >> loan;
cout << "Number of Years: ";
double years;
cin >> years;
double i = .05;
do {
loan + years;
i + 0.125;
cout << "Interest Rate\t\t" << "Monthly Payment\t\t" << "Total Payment\n" << i <<endl;
system("PAUSE");
}while (i <= .08);
}
-
October 6th, 2009, 02:52 AM
#2
Re: Help Please: Comparing loans w/ various interest rates
Before starting to code, you need to have the pseudo code of your algorithm, or at least a good mathematical formula. See http://en.wikipedia.org/wiki/Compound_interest
-
October 6th, 2009, 04:16 AM
#3
Re: Help Please: Comparing loans w/ various interest rates
Hello, are you providing software and IT services for banks
I would also like to find a customer in the bank too, but I don't know how.
Although I am a slow student and I am bad at language use I think I can make similar programs to pay for the classes I take.
-
October 6th, 2009, 11:00 AM
#4
Re: Help Please: Comparing loans w/ various interest rates
Hi, I hope this code will help you compare loans vs interest rates.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double Principal; // original principal
double IntRate; // interest rate, such as 0.05 (5 %)
double PayPerYear; // number of payments per year
double NumYears; // number of years
double Payment; // the regular payment
double numer, denom; // temporary work variables
double b, e; // base and exponent for call to pow()
double Interest;
cout << "Enter principal: ";
cin >> Principal;
cout << "Enter interest rate (i.e., 0.05): ";
cin >> IntRate;
cout << "Enter number of payments per year: ";
cin >> PayPerYear;
cout << "Enter number of years: ";
cin >> NumYears;
cin.ignore();
numer = IntRate * Principal / PayPerYear;
e = -(PayPerYear * NumYears);
b = (IntRate / PayPerYear) + 1;
denom = 1 - pow(b, e);
Payment = numer / denom;
Interest = (Payment * PayPerYear * NumYears) - Principal;
cout << "Payment: " << Payment << "/ month" << endl;
cout << "Total interest: " << Interest;
cin.get();
}
/*Enter principal: 1000
Enter interest rate (i.e., 0.05): 0.05
Enter number of payments per year: 12
Enter number of years: 5
Payment: 18.87 / month
Total interest: 132.27 */
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|