Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How I fix this source code with these problems 1) There can be absolutely no global variables meaning that: float sellprice, rateinter, years; must be

How I fix this source code with these problems 1) There can be absolutely no global variables meaning that: float sellprice, rateinter, years; must be declared in main(). 2) main() must call inputdata(), calculate() AND output(). 3) calculate() must call ONE function (not three separate functions to compute amount of loan, down payment and mortgage payment. 4) Property tax and insurance amounts are incorrect since you have used annual amounts instead of dividing by 12 for monthly amounts#include #include #include #include

using namespace std;

#define YEARLY_TAX_RATE 1.25

#define utilities 300.00

#define insurance 500.00

void intputdata(); void calculate();

float downPayment(float sellprice);

float loanAmount(float sellprice, float downpay);

float mortgagePayment(float loanAmt);

void output(float DownPay, float LoanAmt, float MortgagePay, float PropertyTax);

float sellprice, rateinter, years;

int main()

{

intputdata();

calculate();

system("pause");

return 0;

}

void intputdata()

{

/* Pre: sellprice - the price of the house sell rateinter - the rate of interest years - the year when you bought the house Post:nothing Purpose: Get all needed information for calculate */

cout << "Enter selling price:\t";

cin >> sellprice;

cout << "Enter rate of interest:\t";

cin >> rateinter;

cout << "Enter The number of years:\t";

cin >> years;

}

void calculate()

{

/* Pre:DownPay - down payment LoanAmt - The amount of loan MonthPay - month payment PropertyTax - property tax Post:nothing Purpose:To get all the number for output */

float DownPay,LoanAmt,MonthPay,PropertyTax; PropertyTax = (sellprice *YEARLY_TAX_RATE) / 100;

DownPay = downPayment(sellprice); // Call to downPayment function

LoanAmt = loanAmount(sellprice, DownPay); //call to loanAmount function

MonthPay = mortgagePayment(LoanAmt); //call to mortgagePayment

output(DownPay, LoanAmt, MonthPay, PropertyTax); //call to display function

}

float downPayment(float sellprice) {

/* Pre: sellprice - the price of the house when it sell Post:nothing Purpose:Compute the down payment */

float downpay; downpay = (sellprice * 20)/100; return downpay;

}

float loanAmount(float sellprice, float downpay)

{

/* Pre:downpay - down payment Post:nothing Purpose:To calculate the amount of loan */

float loanAmount;

loanAmount = sellprice - downpay;

return loanAmount;

}

float mortgagePayment(float loanAmt)

{

/* Pre: loanAmt - The amount of loan Post:nothing Purpose:To calculate the mortgage */

float MortgagePay; MortgagePay = (loanAmt * pow((1 + rateinter / (12 * 100)), years * 12) * rateinter / (12 * 100)) / (pow((1 + rateinter / (12 * 100)), (years * 12)) - 1);

return MortgagePay;

}

void output(float DownPay, float LoanAmt, float MortgagePay, float PropertyTax)

{

/* Pre: nothing Post:The MONTHLY COST OF HOUSE and MONTHLY PAYMENT Purpose: Show all the output */

cout << setprecision(2) << fixed; cout << endl;

cout << "******** MONTHLY COST OF HOUSE **********" << endl << endl;

cout << "SELLING PRICE:\t"<< setw(10)<<"$"<< sellprice << endl;

cout << "DOWN PAYMENT:\t" << setw(10) << "$" << DownPay << endl;

cout << "AMOUNT OF LOAN:\t" << setw(10) << "$" << LoanAmt << endl; cout << "INTEREST RATE:\t" << setw(18) << rateinter << "%" << endl;

cout << "TAX RATE:\t" << setw(18) << YEARLY_TAX_RATE << "%" << endl;

cout << "DURATION OF LOAN(YEARS): " << setw(10) << years;

cout << endl << endl; cout << "******** MONTHLY PAYMENT **********" << endl << endl;

cout << "MORTGAGE:\t" << setw(10)<<"$" << MortgagePay << endl;

cout << "UTILITIES:\t" << setw(11) << "$" << utilities << endl;

cout << "PROPERTY TAXES:\t" << setw(10) << "$" << PropertyTax << endl;

cout << "INSURENCE:\t" << setw(11) << "$" << insurance << endl;

cout << setw(20) <<"____________________________________" << endl;

cout << setw(25) << "$" << MortgagePay+insurance+PropertyTax+utilities << endl;

}

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

Step: 3

blur-text-image

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

3. Write reader-centered front matter.

Answered: 1 week ago