Hello everyone! I recently started programming 2 weeks ago and for one of the practice assignments I keep on getting an output of 0.00 no matter what number I plug in. I have spent two hours on this and still have the same issue .
Only one aspect of this code works, when I plug in a negative number I get the output of "Error".
Here is the assignment (I don't think you need to read this to uncover the error):
In this part of the prelab exercise you will write a program to help a prospective home buyer determine the amount of GST payable on a new home. Your program must prompt the user for the purchase price of the home and then print the GST payable on the screen. If the purchase price is negative, your program must print an error message and do nothing else. You should assume that the purchase price is an integer (in other words, a house is unlikely to have a selling price of 1.2 million dollars and 42 cents!)
We'll assume that the GST payable on a new home is computed as follows (note, these aren't the rules that are actually used but they're close)
- the gross amount of tax payable is computed as 5% of the purchase price of the home
- a rebate on the tax computed in step 1 is then calculated according to the following scheme:
- if the purchase price is less than or equal to $350,000.00, then the rebate is 36% of the value computed in step 1) to a maximum of $5,000.00
- if the purchase price is strictly between $350,000.00 and $450,000.00, then the rebate is computed as: 5,000*(450,000.00-purchase price)/100,000.00
- if the purchase price is $450,000.00 or more, then there is no rebate
- The GST payable is the amount computed in step (1) less the amount computed in step (2)
As for my code:
Code:
/*Author: Justin Liang
Date: Sept 23 2011
Purpose: Finds GST payable on a house
Prelab 2.2
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define GST 0.05
int main( void )
{
int houseprice;
double rebate;
double gross_gst;
double gst_payable;
printf( "What is the cost of the house\?\n" );
scanf( "%i", &houseprice );
gross_gst = houseprice*GST;
if( houseprice<0 )
{
printf( "Error\n" );
}
else
{
if( houseprice<=350000 )
{
rebate = 0.36*houseprice;
if( rebate>5000 )
{
rebate = 5000;
}
}
else
{
if( houseprice>350000 && houseprice<450000 )
{
rebate = 5000*(450000-houseprice)/100000;
}
else
{
rebate = 0;
}
}
gst_payable = gross_gst-rebate;
printf( "Your GST payable is %.2f\n" );
}
system( "PAUSE" );
return 0;
}