Tax Calulator Assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bobozelda
    New Member
    • Mar 2008
    • 5

    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
    [code=c]
    /*Tax calculator for Kudler Fine Foods*/

    /*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_c alculator();

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

    return 0;

    }

    float tax_calculator (void)

    {

    float 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 ("%.2lf", &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 ("%.2lf", &iOperand1);

    getchar();

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

    getchar();

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

    getchar();

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

    getchar();

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

    iOperand1=getch ();

    return iOperand1;

    }[/code]
    Last edited by sicarie; Mar 5 '08, 04:40 AM. Reason: code tags, removing name
  • albs
    New Member
    • Mar 2008
    • 3

    #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.

    Comment

    • bobozelda
      New Member
      • Mar 2008
      • 5

      #3
      Originally posted by albs
      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!!!

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #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.

        Comment

        • bobozelda
          New Member
          • Mar 2008
          • 5

          #5
          Originally posted by weaknessforcats
          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_c alculator();

          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;

          }

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            I get 9.06 running your code using Visual Studio.NET 2005.

            Comment

            • bobozelda
              New Member
              • Mar 2008
              • 5

              #7
              Originally posted by weaknessforcats
              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!!!).

              Comment

              • bobozelda
                New Member
                • Mar 2008
                • 5

                #8
                Originally posted by bobozelda
                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;

                }

                Comment

                Working...