Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- struct loan
- {
- float amount;
- float rate;
- int id;
- int term;
- };
- float payment(float amount,float rate, int term);
- int main()
- {
- loan loan1;
- int monthly_payment;
- float amount;
- cout<<" Enter The ID of this loan:" ;
- cin>>loan1.id;
- cout<<" Enter the amont of this load";
- cin>>loan1.amount;
- cout<< " Enter the annual Interest rate of this load In % (e.g., 5.4): ";
- cin >>loan1.rate ;
- cout<< " Enter the term (number of onths, length of loan): ";
- cin>>loan1.term;
- monthly_payment = payment(amount, rate,term);
- cout<< " The monthly payment for loan " << id << " is: " << monthly_payment << endl;
- return 0;
- }
- float payment(float amount,float rate, int term)
- {
- rate = rate/1200; // to convert % yearly rate to monthly fraction
- return amount*rate*(pow((rate+1), term)/(pow((rate+1), term)-1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement