472,791 Members | 1,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

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 5446
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,208 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,208 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

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

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
10
by: Andrew Koenig | last post by:
It has been pointed out to me that various C++ books disagree about the relative precedence of ?: and the assignment operators. In order to satisfy myself about the matter once and for all, I...
5
by: CoolPint | last post by:
It seems to me that I cannot assign objects of a class which has a constant data member since the data member cannot be changed once the constructor calls are completed. Is this the way it is meant...
16
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
9
by: Rick N. Backer | last post by:
I have an abstract base class that has char* members. Is an assignment operator necessary for this abstract base class? Why or why not? Thanks in advance. Ken Wilson Amer. Dlx. Tele,...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
6
by: Neil Zanella | last post by:
Hello, I would like to know whether the following C fragment is legal in standard C and behaves as intended under conforming implementations... union foo { char c; double d; };
35
by: nagy | last post by:
I do the following. First create lists x,y,z. Then add an element to x using the augumented assignment operator. This causes all the other lists to be changed also. But if I use the assignment...
20
by: TimeHorse | last post by:
I would like to gauge interest in the following proposal: Problem: Assignment statements cannot be used as expressions. Performing a list of mutually exclusive checks that require data...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.