0

Basically I've finished my code for the most part and I'm having trouble figuring out how to initialize loan, mort_gage, and downpayment. Is it possible to use a pointer for each of these and call the address back to main? I'm so confused...it's just one of those little things that's driving me crazy.

```
#include<stdio.h>
#include<math.h>
#define PROPERTY_TAX_RATE 0.0125
#define COST_OF_UTILITIES 300.00
#define COST_OF_INSURANCE 500.00
void getData(double* pPrice, double* pInterest_rate,double* pYears);
double calcData(double pPrice, double pInterest_rate, double pYears, double downpayment,double* pUtilities,
double* pProp_tax,double* pInsurance,double* ptotal,double mort_gage, double loan);
void calcLoan(double* pLoan,double* pNumber_compounding,double* pDownpayment, double* pMort_gage,
double pPrice, double pYears, double pInterest_rate);
void output(double pPrice, double years, double interest_rate, double prop_tax, double insurance,
double downpayment,double mort_gage, double utilities,double loan,double total);
int main (void)
{
//Local Declarations
double price;
double interest_rate;
double years;
double downpayment;
double loan;
double utilities;
double prop_tax;
double insurance;
double mort_gage;
double total;
getData(&price, &interest_rate, &years);//Good
calcData(price, interest_rate, years, downpayment,&utilities, &prop_tax, &insurance,&total,mort_gage,loan);
output(price,years,interest_rate,prop_tax,insurance,downpayment,mort_gage,utilities,loan,total);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void getData(double* pPrice, double* pInterest_rate,double* pYears)
{
//Asks for price
printf("Enter the price: ");
scanf("%lf",&pPrice);
//Asks for interest rate
printf("Enter the interest rate: ");
scanf("%lf",&pInterest_rate);
//Asks for the number of years
printf("Enter the number of years: ");
scanf("%lf",&pYears);
return;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
double calcData(double pPrice, double pInterest_rate, double pYears, double downpayment,double* pUtilities,
double* pProp_tax,double* pInsurance,double* ptotal,double mort_gage, double loan)
//total, property taxes = 1.25%/ 12, utilities divide by 12
{
double number_compounding;
//Calculates Utilities
*pUtilities = COST_OF_UTILITIES;
//Calculates Property Taxes
*pProp_tax = (PROPERTY_TAX_RATE* pPrice)/12;
//Computes Insurance
*pInsurance = COST_OF_INSURANCE;
//Calculates the total
*ptotal = *pUtilities + *pInsurance + *pProp_tax;
//Loan Function
calcLoan(&loan,&number_compounding, &downpayment, &mort_gage,pPrice, pYears, pInterest_rate);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void calcLoan(double* pLoan,double* pNumber_compounding,double* pDownpayment, double* pMort_gage,
double pPrice, double pYears, double pInterest_rate)
//downpayment, amount of loan, and monthly mortgage
{
*pNumber_compounding = pYears*12;
//loan calculations
*pLoan = pPrice*((pow((1+pInterest_rate),*pNumber_compounding))-1)/((pInterest_rate)*(pow((1+pInterest_rate),*pNumber_compounding)));
//downpayment
*pDownpayment = pPrice*0.2;
//mortgage
*pMort_gage = (*pLoan*(pInterest_rate*pow((1+pInterest_rate),*pNumber_compounding)))/(pow((1+pInterest_rate),*pNumber_compounding) - 1);
return;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void output(double pPrice, double years, double interest_rate, double prop_tax, double insurance,
double downpayment,double mort_gage, double utilities, double loan,double total)
{
printf("MONTHLY COST OF HOUSE\n");
printf("SELLING PRICE $%.2lf\n",pPrice);
printf("DOWN PAYMENT $%.2lf\n",downpayment);
printf("AMOUNT OF LOAN $%.2lf\n",loan);
printf("INTEREST RATE $%.2lf%%",interest_rate);
printf("TAX RATE $%.2lf%%",prop_tax);
printf("DURATION OF LOAN (YEARS) %d",(int)years);
printf("\n");
printf("MONTHLY PAYMENT\n");
printf("\tMORTGAGE: %lf",mort_gage);
printf("UTILITIES: %lf",utilities);
printf("PROPERTY TAXES: %lf",prop_tax);
printf("INSURANCE: %lf\n", insurance);
printf("__________\n");
printf("$.2lf",total);
return;
}
```