-
Scanf
No matter what figure I input. It come out the same figure. Please help me. I think there are some thing wrong of " scanf(%ld0". Please help me. thanks a lot.
#include <stdio.h>
long tax_in,tax_pay; //tax_in=taxable income,tax_pay=tax payable
main()
{
printf("Please input your amount of taxable income or input -9999 to exit the program.\n");
scanf ("%ld" , &tax_in);
while (tax_in !=-9999)
{
if ((tax_in>0) && (tax_in<999999))
{
if ((tax_in>0) && (tax_in<=20000))
tax_pay=tax_in*0.02;
else
if ((tax_in>20000) && (tax_in<=50000))
tax_pay=(tax_in-20000)*0.07+400;
else
if ((tax_in>50000) && (tax_in<=100000))
tax_pay=(tax_in-50000)*0.15+2500;
else
if ((tax_in>100000) && (tax_in<=999999))
tax_pay=(tax_in-100000)*0.20+10000;
printf( "Your tax payable is %ld\n", &tax_in);
}
else
printf ( "Invalid amount, please try again.\n");
printf ( "Enter taxable income: ");
scanf ("%ld" , &tax_in);
}
}
-
S Lee,
Look at you last line in your while:
Code:
printf( "Your tax payable is %ld\n", &tax_in);
The variable you are printing is the same variable the user entered. It should be:
Code:
printf("Your tax payable is %ld\n", tax_pay);
Also, why declare them as longs? If I remember correctly a long and an int both are 4 bytes.
Another thing, it seems like you have a few braces missing inside your while (on the nested if-else's), may wanna double check that.
{forgot that printf's don't take addresses}
-
printf( "Your tax payable is %ld\n", &tax_in);
You aren't supposed to pass addresses to printf. Just pass the variable itself...
printf( "Your tax payable is %ld\n", tax_in);