Advertisement
Guest User

Interesting!

a guest
Jan 16th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // A practice program to calculate a (theoretical) loan payment scheme
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.     double Principal, IntRate, PayPerYear, NumYears, Payment, numer, denom, b , e, TotalInterest = 0.0;
  9.     double runningtotal, monthcount;
  10.    
  11.     cout << "What is the principal?\n";
  12.     cin >> Principal;
  13.    
  14.     cout << "What is the interest rate?\n";
  15.     cin >> IntRate;
  16.    
  17.     cout << "How many payments per year?\n";
  18.     cin >> PayPerYear;
  19.    
  20.     cout << "How many years of payment?\n";
  21.     cin >> NumYears;
  22.    
  23.     numer = IntRate*(Principal/PayPerYear);
  24.    
  25.     e = -(PayPerYear * NumYears);
  26.     b = (IntRate/PayPerYear)+1;
  27.    
  28.     denom = 1 - pow(b, e);
  29.    
  30.     Payment = numer / denom;
  31.    
  32.     cout << "Payment is " << Payment;
  33.     runningtotal = Principal;
  34.  
  35.     for(monthcount = (NumYears*12); monthcount >= 0; --monthcount) {
  36.        
  37.         TotalInterest += (IntRate * runningtotal);
  38.         cout << "\n" << TotalInterest;
  39.         runningtotal -= Payment;
  40.         }
  41.  
  42.  cout << "\nPayment is " << Payment << "\n Total interest payed is " << TotalInterest << "\n";
  43.  
  44.     system("pause");
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement