Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
#include
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 ";
cin >> loan1.ID;
cout << "Enter the amount of this loan ";
cin >> loan1.amount;
cout << "Enter the annual interest rate of this loan (in %) ";
cin >> loan1.rate;
cout << "Enter the term (number of months, length of the loan) ";
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

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

=+What kinds of problems need to be overcome?

Answered: 1 week ago

Question

=+Describe an important trade-off you recently faced

Answered: 1 week ago