Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. struct loan
  8. {
  9. float amount;
  10. float rate;
  11. int id;
  12. int term;
  13. };
  14.  
  15.  
  16. float payment(float amount,float rate, int term);
  17.  
  18. int main()
  19.  
  20. {
  21. loan loan1;
  22. int monthly_payment;
  23. float amount;
  24.  
  25.  
  26.  
  27. cout<<" Enter The ID of this loan:" ;
  28. cin>>loan1.id;
  29.  
  30. cout<<" Enter the amont of this load";
  31. cin>>loan1.amount;
  32. cout<< " Enter the annual Interest rate of this load In % (e.g., 5.4): ";
  33. cin >>loan1.rate ;
  34.  
  35. cout<< " Enter the term (number of onths, length of loan): ";
  36. cin>>loan1.term;
  37.  
  38.  
  39. monthly_payment = payment(amount, rate,term);
  40.  
  41. cout<< " The monthly payment for loan " << id << " is: " << monthly_payment << endl;
  42. return 0;
  43.  
  44.  
  45. }
  46.  
  47. float payment(float amount,float rate, int term)
  48. {
  49.  
  50.  
  51. rate = rate/1200; // to convert % yearly rate to monthly fraction
  52. return amount*rate*(pow((rate+1), term)/(pow((rate+1), term)-1));
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement