468,512 Members | 1,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Tax Calulator Assignment

I have an assignment where I am prompted to enter a number and the program will figure the tax on the amount entered. This will be for 3 separate store locations. I finally have the program displaying correctly on the screen, but the math is no good and it won't figure to the dollars and cents (tax is on 125.00 at 3 fifferent tax rates). I am using %.2f in the scanf and printf areas, but I have to get the program to recognize the floating point, not integers. Below is the code. PLease, could someone give me some advice. Class is on thursday and I still need to do a flowchart in Visio.

Thank you
Expand|Select|Wrap|Line Numbers
  1. /*Tax calculator for Kudler Fine Foods*/
  2.  
  3. /*This program is designed to calculate the tax on the taxable dollar amount of each purchase at each Kudler Fine Foods store*/
  4.  
  5. #include<stdio.h>
  6.  
  7. int main (void)
  8.  
  9. {
  10.  
  11. int tax_input;
  12.  
  13. tax_input=tax_calculator();
  14.  
  15. printf ("%.2f\n", tax_input);
  16.  
  17. return 0;
  18.  
  19.  
  20. float tax_calculator (void)
  21.  
  22. {
  23.  
  24. float iOperand1;
  25.  
  26. printf ("\nKudler Fine Foods tax calculator\n");
  27.  
  28. printf ("\nEnter the amount of the total purchase that is taxable at the Del Mar location: ");
  29.  
  30. getchar();
  31.  
  32. scanf ("%.2lf", &iOperand1);
  33.  
  34. getchar();
  35.  
  36. printf ("The tax on the purchase at the Del Mar location is %.2f\n", iOperand1*.0725);
  37.  
  38. getchar();
  39.  
  40. printf ("\nEnter the amount of the total purchase that is taxable at the Encinitas location: ");
  41.  
  42. getchar();
  43.  
  44. scanf ("%.2lf", &iOperand1);
  45.  
  46. getchar();
  47.  
  48. printf ("The tax on the purchase at the Encinitas location is %2.f\n", iOperand1*.075);
  49.  
  50. getchar();
  51.  
  52. printf ("\nEnter the amount of the total purchase that is taxable at the La Jolla location: ");
  53.  
  54. getchar();
  55.  
  56. scanf ("%.2lf", &iOperand1);
  57.  
  58. getchar();
  59.  
  60. printf ("The tax on the purchase at the La Jolla location is %.2f\n", 
  61. iOperand1*.0775);
  62.  
  63. iOperand1=getch();
  64.  
  65. return iOperand1;
  66.  
  67. }
Mar 5 '08 #1
7 5212
albs
3
on your scanfs you have %.2lf not .2f. your trying to scan in a double.. not a float.. maybe thats the problem.. i didnt read the code over but thats something i saw quick.
Mar 5 '08 #2
on your scanfs you have %.2lf not .2f. your trying to scan in a double.. not a float.. maybe thats the problem.. i didnt read the code over but thats something i saw quick.
Thank you for the reply. I cleaned up the %.2fs. I tried it and got the same results. I had originally changed the floats at the top of the code back to int. I had originally changed it in the hope that the %.2fs would work. No such luck. The program is functioning like it should, the math just doesn't work. I won't recognize the floating point numbers. I know that there is something wrong in my setup, but this is my virgin code and I am feeling my way in the dark (I know so very little).

Thanks again. Anyone out there with an idea.., HELP!!!
Mar 5 '08 #3
weaknessforcats
9,207 Expert Mod 8TB
One thing you should do is to remove the floating-point and use integers instead. Keep the money in pennies. I'm sure you can write a functon that can display an integer containing 123 as $1.23.

Floating-point does not work for money due to the rounding and limits on thne number of significant digits. Further the operators like <, > ==, etc may report a condition as true when it isn't. You should Google floating point arithmetic for a real eyeful.

There are laws in Europe against using floaring-point in financial calculations.
Mar 5 '08 #4
One thing you should do is to remove the floating-point and use integers instead. Keep the money in pennies. I'm sure you can write a functon that can display an integer containing 123 as $1.23.

Floating-point does not work for money due to the rounding and limits on thne number of significant digits. Further the operators like <, > ==, etc may report a condition as true when it isn't. You should Google floating point arithmetic for a real eyeful.

There are laws in Europe against using floaring-point in financial calculations.
This morning, I executed my latest code and it's actually working at about 90%. When executed, it runs correct (allows the user to enter numbers, it performs tax calculations, it displays the results of those calculations, and it stays on the screen like it should). The only problem that I am having is that the resulting tax at the first location calculates the tax incorrectly (125.00 x .0725 does not equal 1.81, it should read 9.06). I am glad to say that the tax at the last two locations do calculate correctly. All I need now is to figure out why the tax for the first listed location (Del Mar) won't calculate correctly.
Also, thank you to all of you who have been kind enough to offer suggestions. It's quite generous of you!

/*Tax calculator for Kudler Fine Foods*/
//by James Johnson

/*This program is designed to calculate the tax on the taxable dollar amount of each purchase at each Kudler Fine Foods store*/

#include<stdio.h>

int main (void)

{

int tax_input;

tax_input=tax_calculator();

printf ("%.2f\n", tax_input);

return 0;

}

int tax_calculator (void)

{

int iOperand1;

printf ("\nKudler Fine Foods tax calculator\n");

printf ("\nEnter the amount of the total purchase that is taxable at the Del Mar location: ");

getchar();

scanf ("%.2f", &iOperand1);

getchar();

printf ("The tax on the purchase at the Del Mar location is %.2f\n", iOperand1*.0725);

getchar();

printf ("\nEnter the amount of the total purchase that is taxable at the Encinitas location: ");

getchar();

scanf ("%.2f", &iOperand1);

getchar();

printf ("The tax on the purchase at the Encinitas location is %.2f\n", iOperand1*.075);

getchar();

printf ("\nEnter the amount of the total purchase that is taxable at the La Jolla location: ");

getchar();

scanf ("%.2f", &iOperand1);

getchar();

printf ("The tax on the purchase at the La Jolla location is %.2f\n", iOperand1*.0775);

iOperand1=getch();

return iOperand1;

}
Mar 5 '08 #5
weaknessforcats
9,207 Expert Mod 8TB
I get 9.06 running your code using Visual Studio.NET 2005.
Mar 5 '08 #6
I get 9.06 running your code using Visual Studio.NET 2005.
Thanks for the reply. In doing some figuring, I just discovered that when I execute my program (I'm using Miracle C, since that is what my school is having us use), the first location figures the tax at a rate of .01448. It seems to be ignoring the .0725 in the calculation (I changed the tax rate for that location & it still came up at 1.81. I then changed the number that I input and the amount then changed (the resulting amount was still .01448 of the entered amount), so it appears that the program is taking the tax rate from somewhere other than from the calculation. My question is..., WHERE!!!).
Mar 5 '08 #7
Thanks for the reply. In doing some figuring, I just discovered that when I execute my program (I'm using Miracle C, since that is what my school is having us use), the first location figures the tax at a rate of .01448. It seems to be ignoring the .0725 in the calculation (I changed the tax rate for that location & it still came up at 1.81. I then changed the number that I input and the amount then changed (the resulting amount was still .01448 of the entered amount), so it appears that the program is taking the tax rate from somewhere other than from the calculation. My question is..., WHERE!!!).
Thanks for the suggestions. My teacher fixed my code last night in class. Below is the right code. Again, thanks.

/*Tax calculator for Kudler Fine Foods*/
//by James Johnson

/*This program is designed to calculate the tax on the taxable dollar amount of each purchase at each Kudler Fine Foods store*/

#include<stdio.h>

int main (void)

{

int tax_input;


tax_calculator();



return 0;

}

int tax_calculator (void)

{

float iOperand1=0.0;

printf ("\nKudler Fine Foods tax calculator\n");

printf ("\nEnter the amount of the total purchase that is taxable at the Del Mar location: ");



scanf ("%f", &iOperand1);



printf ("The tax on the purchase at the Del Mar location is %.2f\n", iOperand1*.0725);



printf ("\nEnter the amount of the total purchase that is taxable at the Encinitas location: ");



scanf ("%f", &iOperand1);



printf ("The tax on the purchase at the Encinitas location is %.2f\n", iOperand1*.075);



printf ("\nEnter the amount of the total purchase that is taxable at the La Jolla location: ");



scanf ("%f", &iOperand1);



printf ("The tax on the purchase at the La Jolla location is %.2f\n", iOperand1*.0775);

getch();



return 0;

}
Mar 7 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

23 posts views Thread by Paul Rubin | last post: by
10 posts views Thread by Andrew Koenig | last post: by
16 posts views Thread by Edward Diener | last post: by
9 posts views Thread by Rick N. Backer | last post: by
166 posts views Thread by Graham | last post: by
6 posts views Thread by Neil Zanella | last post: by
20 posts views Thread by TimeHorse | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.