473,385 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 5482
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.