Hi,
I need help with this code below. Can't seem to get it to work with this description. Can someone adjust it for me please?
To calculate the 15 year total cost add the initial cost of the house to the electric bill for 15 years and the water and sewer bill for 15 years, to this add the taxes for 15 years. To calculate the taxes for one year multiply the tax rate by the initial cost of the house. Align all numbers on the right hand side. Do not display decimal digits except for the tax rate.
#include <stdio.h>
#include <stdlib.h>
#define HOUSECOST 3.8
/* This program calculates the cost of a house for 15 years */
int main(void)
{
int initialcost, electricbill, waterandsewer, taxrate,total;
printf("\n How much is your house? ");
scanf("%d", &initialcost);
printf("\n How much is your electric bill? ");
scanf("%d", &electricbill);
printf("\n How much is your water and sewer? ");
scanf("%d", &waterandsewer);
printf("\n How much is your tax rate? ");
scanf("%d", &taxrate);
initialcost = electricbill * waterandsewer * taxrate;
total = initialcost * HOUSECOST;
printf ("\n Ron A ");
printf ("\n Initial Cost = %d", initialcost);
printf ("\n Electric Bill = %d", electricbill);
printf ("\n Water And Sewer = %d" , waterandsewer);
printf ("\n Tax Rate = %3.8" , taxrate);
printf ("\n Total = %15d\n" , total);
system("pause");
return (0);
}
You need to look up how to format your output. Also, your formula for initialcost is incorrect. You need a + in there somewhere.
You also have a logic error. The prices will be entered in terms of dollars and cents, I assume. Since the variables you designated to store the data are all ints, any decimals will be truncated. The tax rate also needs to be adjusted from a percentage. If the tax rate is 7.5% then the taxrate variable should be divided by 100 to get 0.075. With an int, the result would be 0, changing your entire output to 0. Try using floats or doubles instead.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks