Solved
Program computes the annual after_tax cost of a new house
Posted on 2005-04-12
Topic: Write a program that computes the annual after_tax cost of a new house for the first year of ownership. The cost is computed aa 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 toward paying off the 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 interst payments are tax deductible. So the tax savings is 35% of the interst payment.
This is my program.
#include <iostream.h>
#include <stdlib.h>
#define DEBUG true
double initial(double price, double down_payment);
double mortgage(double initial);
double taxrate(double price);
double housecost(double mortgageCost, double taxrate);
int main()
{
char ans;
double price, down_payment;
double initial, mortgageCost, tax, cost;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
do
{
//Get input from the user
cout << "Enter the price of the house: ";
cin >> price;
cout << "Enter your down payment): ";
cin >>down_payment;
//Output result
cout <<"The initial loan balance is "<<initial(price, down_payment)<<endl;
cout <<"The annual mortgage cost is "<<mortgage(initial)<<endl;
cout <<"The tax saving is "<<taxrate(price)<<endl;
cout <<"The cost of a new house for the first year of ownership is "<<housecost(mortgage, taxrate);
//Ask user if wanting to calculate again
cout <<"Start it again?\n"
<<"Press y for yes, no for no,\n"
<<"and then press return: ";
cin >>ans;
cout <<endl;
} while (ans == 'y' || ans == 'Y');
system("PAUSE");
return 0;
}
double initial(double price, double down_payment)
/*********************************************************************
Function Name: initial
Purpose: Calculate the initial loan
Arguments: price, down_payment
Returns: initial
*********************************************************************/
{
if (DEBUG)
{
cout <<"The initial loan balance is: "<<initial;
cout <<endl;
}
return (price - down_payment);
}
double mortgageCost (double initial)
/*********************************************************************
Function Name: mortgage_cost
Purpose: Calculate the mortgae cost
Arguments: initial_loan
Returns: mortgage cost
*********************************************************************/
{
if (DEBUG)
{
cout <<"The annual mortgage cost is: "<<mortgage(initial);
cout <<endl;
}
const double loan_balance = 0.03; //3% of initial loan balance
const double loan_interest = 0.06; //6% of the initial loan balance in intersest
double total;
loan_balance = (initial_loan * 0.03);
loan_interest = (initial_loan * 0.06);
total = loan_balance + loan_interest;
return (total);
}
double taxrate(double price)
/*********************************************************************
Function Name: tax
Purpose: Calculate the tax
Arguments: price
Returns: tax
*********************************************************************/
{
if (DEBUG)
{
cout <<"The tax saving is "<<taxrate;
cout <<endl;
}
const double interest_payment = 0.35; //35% of the interest payment
return (housecost * interest_payment);
}
double housecost(double mortgage, double taxrate)
/*********************************************************************
Function Name: cost
Purpose: Calculate the cost of the house for the first year of ownership
Arguments: mortgage, taxreate
Returns: cost of the house for first year of ownership
*********************************************************************/
{
if (DEBUG)
{
cout <<"The cost of a new house for the first year of ownership is "
<<housecost<<endl;
}
return (mortgage - taxrate);
}
I dont know what wrong with this program, can someone help???