18.8k views
0 votes
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two inputs, current price and last month's price (both integers). Then, output a summary listing the price, the change since last month, and the estimated monthly mortgage computed as (currentPrice * 0.045) / 12. Ex: If the input is 200000 210000, the output is:_____

This house is $200000.
The change is $-10000 since last month.
The estimated monthly mortgage is $750.0.

User Lee White
by
5.3k points

1 Answer

3 votes

Answer:

Since the programming language is not specified in the question, we will write the code in C++ language.

The C++ code along with comments for explanation and output results are provided below.

C++ Code with Explanation:

#include <iostream>

using namespace std;

int main()

{

int CurrentMonthPrice;

int LastMonthPrice;

int ChangeInPrice;

// since the value of mortgage can result in fraction so we will use float type for it

float MonthlyMortgage;

// get the current month price from the user

cout<<"Input the current month price: ";

cin>>CurrentMonthPrice;

// get the last month price from the user

cout<<"Input the last month price: ";

cin>>LastMonthPrice;

// compute the change in price since last month

ChangeInPrice = CurrentMonthPrice - LastMonthPrice;

// compute the monthly mortgage of the house as per the formula given in the question

MonthlyMortgage = (CurrentMonthPrice*0.045)/12;

// print the output summary

// print the current price of the house

cout<<"This house is $"<<CurrentMonthPrice<<endl;

//Print the change in the price of the house since last month

cout<<"The change is $"<<ChangeInPrice<<" since last month"<<endl;

// print the estimated monthly mortgage

cout<<"The monthly mortgage is $"<<MonthlyMortgage<<endl;

return 0;

}

Output:

Input the current month price: 200000

Input the last month price: 210000

This house is $200000

The change is $-10000

The monthly mortgage is $750

Sites like Zillow get input about house prices from a database and provide nice summaries-example-1
User Henk Straten
by
4.5k points