Question: Modify the program below such that it asks users to enter 2 different loans this time and uses a function called initialize_loan to initialize each

Modify the program below such that it asks users to enter 2 different loans this time and uses a function called initialize_loan to initialize each loan struct. The program should also compute and display the payment for each individual loan and the total monthly payment. Use a separate struct for each loan.

#include<iostream>

#include<cmath>

using namespace std;

struct Loan // Loan is called structure tag

{

int ID; // assume an unique integer between 1111-9999

float amount; // $ amount of the loan

float rate; // annual interest rate

int term; // number of months, length of the loan

};

float payment(Loan l);

int main( )

{

Loan loan1;

float monthly_payment;

// Initialize the loan1 structure

cout << "Enter the ID of this loan \n";

cin >> loan1.ID;

cout << "Enter the amount of this loan \n";

cin >> loan1.amount;

cout << "Enter the annual interest rate of this loan (in %) \n";

cin >> loan1.rate;

cout << "Enter the term (number of months, length of the loan) \n";

cin >> loan1.term;

monthly_payment = payment(loan1);

cout << "The monthly payment for loan " << loan1.ID << " is: " << monthly_payment << endl;

return 0;

}

float payment(Loan l)

{

l.rate = l.rate/1200; // To convert % yearly rate to monthly fraction

return l.amount*l.rate*( pow( (l.rate+1), l.term)/ (pow( (l.rate+1), l.term) - 1) );

}

Step by Step Solution

3.42 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To satisfy the requirements for modifying the program we will 1 Create a function called initializeloan to initialize each loan struct 2 Adjust the ma... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!