8. Write a program that computes the annual after-tax cost of a new house
for the first year of ownership. The cost is computed as the annual mortgage
cost minus the tax savings. The input should be the price of the
house and the down payment. The annual mortgage cost can be estimated
as 3% of the initial loan balance credited towCHAPTER 4 / Procedural Abstraction and Functions That Return a Value
loan principal plus 6% of the initial loan balance in interest. The initial
loan balance is the price minus the down payment. Assume a 35% marginal
tax rate and assume that interest payments are tax deductible. So, the
tax savings is 35% of the interest payment. Your program should use at
least two function definitions. Your program should allow the user to
repeat this calculation as often as the user wishesard paying off the
PROGRAM CODE:
//Header section
#include <iostream>
using namespace std;
// Function to calculate the annual mortgage cost
double calculateMortgageCost(double price, double downPayment) {
double loanBalance = price - downPayment;
double interestPayment = 0.06 * loanBalance;
double mortgageCost = 0.03 * loanBalance + interestPayment;
return mortgageCost;
}
// Function to calculate the tax savings
double calculateTaxSavings(double interestPayment) {
double taxRate = 0.35;
double taxSavings = taxRate * interestPayment;
return taxSavings;
}
//main program
int main()
{
//Declare varaibles
char choice;
do
{
double price, downPayment;
// Get input from the user
cout << "Enter the price of the house: $";
cin >> price;
cout << "Enter the down payment: $";
cin >> downPayment;
// Calculate the annual mortgage cost
double mortgageCost = calculateMortgageCost(price, downPayment);
// Calculate the tax savings
double taxSavings = calculateTaxSavings(0.06 * (price - downPayment));
// Calculate the annual after-tax cost
double afterTaxCost = mortgageCost - taxSavings;
// Output the result
cout << "Annual after-tax cost: $" << afterTaxCost << endl;
// Ask the user if they want to repeat the calculation
cout << "Do you want to calculate again? (Y/N): ";
cin >> choice;
} while (choice == 'Y' || choice == 'y');
return 0;
}
OUTPUT OF THE PROGRAM CODE:
Enter the price of the house: $3500000
Enter the down payment: $500000
Annual after-tax cost: $207000
Do you want to calculate again? (Y/N): y
Enter the price of the house: $2500000
Enter the down payment: $50000
Annual after-tax cost: $169050
Do you want to calculate again? (Y/N): n