Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,401 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,120 people online right now. Registration is fast and FREE... Join Now!




Sales Tax

 
Reply to this topicStart new topic

Sales Tax, Help with calculating sales tax

promiscuoustx
6 Sep, 2006 - 10:25 AM
Post #1

New D.I.C Head
*

Joined: 30 Aug, 2006
Posts: 36


My Contributions
I am trying to perform the following with a sales tax program:

1. Modify the C program so that the user inputs the purchase amount.
2. Check the user’s input for validity.
Here is my code, but it is not calculating the sales tax?? Help please!!

CODE

#include <stdlib.h>
#include <stdio.h>

main()
{

/*Some food items and all non-food items are subject to a statewide sales tax and local*/
/*district taxes.  Due to differences in district taxes, each store uses a different tax rate*/

      int iResponse = 0;
      int PurchaseAmount;
      char str_DelMar[] = "Del Mar", str_Encinitas[] = "Encinitas", str_LaJolla[] = "La Jolla";
      /*The above is the three districts*/
      double tax_DelMar = 7.25, tax_Encinitas = 7.5, tax_LaJolla = 7.75;
      /*The above is the distinct district taxes for the three districts*/
      char s;
      char mychar;
      

/*This is to ensure the user of this program knows what the purpose of this program is*/
printf("\nThis is a program to calculate the taxes on articles\n");
printf("\npurchased at a price the user chooses, depending on the district.\n");

/*The user needs to choose which option they want*/
printf("\nFor the district Del Mar, please press 1.\n");
printf("\nFor the district Encinitas, please press 2.\n");
printf("\nFor the district La Jolla, please press 3.\n");
/*Added the option to exit for users*/
printf("\nTo exit, please press 0.\n");
scanf ("%d", &iResponse);
/*Once the user chooses the district, the user must input the dollar amount of the purchase*/
printf("\nPlease enter the purchase amount.\n");
scanf  ("\n%d", &PurchaseAmount);



if (iResponse == 1){
   printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f\n ",PurchaseAmount,str_DelMar, PurchaseAmount * tax_DelMar / 100 );
}
else {

      if (iResponse == 2)
      printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f ",PurchaseAmount,str_Encinitas, PurchaseAmount * tax_Encinitas / 100 );
else

        if (iResponse == 3)
        printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f ",PurchaseAmount,str_LaJolla, PurchaseAmount * tax_LaJolla / 100 );
}
getch();
return 0;
}  


I am not sure why it is not calculating. Thanks for any help. biggrin.gif

This post has been edited by Videege: 6 Sep, 2006 - 10:31 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Sales Tax
6 Sep, 2006 - 10:31 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Is it calculating an incorrect amount, or none at all?
User is offlineProfile CardPM
+Quote Post

promiscuoustx
RE: Sales Tax
6 Sep, 2006 - 10:37 AM
Post #3

New D.I.C Head
*

Joined: 30 Aug, 2006
Posts: 36


My Contributions
QUOTE(Amadeus @ 6 Sep, 2006 - 11:31 AM) *

Is it calculating an incorrect amount, or none at all?


It displays the following no matter what amount I choose or
which district I choose.

"The tax for the purchase at price $0.00 in district <null> is $0.00"
User is offlineProfile CardPM
+Quote Post

promiscuoustx
RE: Sales Tax
6 Sep, 2006 - 11:37 AM
Post #4

New D.I.C Head
*

Joined: 30 Aug, 2006
Posts: 36


My Contributions
QUOTE(promiscuoustx @ 6 Sep, 2006 - 11:37 AM) *

QUOTE(Amadeus @ 6 Sep, 2006 - 11:31 AM) *

Is it calculating an incorrect amount, or none at all?


It displays the following no matter what amount I choose or
which district I choose.

"The tax for the purchase at price $0.00 in district <null> is $0.00"



I changed int PurchaseAmount to float PurchaseAmount, so at least the district is
showing now, but I am unsure still why the purchase amount and total is not showing. crazy.gif
User is offlineProfile CardPM
+Quote Post

promiscuoustx
RE: Sales Tax
7 Sep, 2006 - 06:34 AM
Post #5

New D.I.C Head
*

Joined: 30 Aug, 2006
Posts: 36


My Contributions
QUOTE(promiscuoustx @ 6 Sep, 2006 - 12:37 PM) *

QUOTE(promiscuoustx @ 6 Sep, 2006 - 11:37 AM) *

QUOTE(Amadeus @ 6 Sep, 2006 - 11:31 AM) *

Is it calculating an incorrect amount, or none at all?


It displays the following no matter what amount I choose or
which district I choose.

"The tax for the purchase at price $0.00 in district <null> is $0.00"



I changed int PurchaseAmount to float PurchaseAmount, so at least the district is
showing now, but I am unsure still why the purchase amount and total is not showing. crazy.gif



I have been racking my brain all night on this as to why my purchase price and sales tax amount
are not showing up. They are both showing as $0.00?? Does anyone have any suggestions??? Here
is my code that I have...
CODE
#include <stdlib.h>
#include <stdio.h>

main()
{

/*Some food items and all non-food items are subject to a statewide sales tax and local*/
/*district taxes.  Due to differences in district taxes, each store uses a different tax rate*/

      int iResponse = 0;
      float PurchaseAmount;
      char str_DelMar[] = "Del Mar", str_Encinitas[] = "Encinitas", str_LaJolla[] = "La Jolla";
      /*The above is the three districts*/
      double tax_DelMar = 7.25, tax_Encinitas = 7.5, tax_LaJolla = 7.75;
      /*The above is the distinct district taxes for the three districts*/
      char s;
      char mychar;
      

/*This is to ensure the user of this program knows what the purpose of this program is*/
printf("\nThis is a program to calculate the taxes on articles\n");
printf("\npurchased at a price the user chooses, depending on the district.\n");

/*The user needs to choose which option they want*/
printf("\nFor the district Del Mar, please press 1.\n");
printf("\nFor the district Encinitas, please press 2.\n");
printf("\nFor the district La Jolla, please press 3.\n");
/*Added the option to exit for users*/
printf("\nTo exit, please press 0.\n");
scanf ("%d", &iResponse);
/*Once the user chooses the district, the user must input the dollar amount of the purchase*/
printf("\nPlease enter the purchase amount.\n");
scanf  ("%d", &PurchaseAmount);



if (iResponse == 1){
   printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f\n ",PurchaseAmount,str_DelMar, PurchaseAmount * tax_DelMar / 100 );
}
else {

      if (iResponse == 2)
      printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f\n ",PurchaseAmount,str_Encinitas, PurchaseAmount * tax_Encinitas / 100 );
else

        if (iResponse == 3)
        printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f\n ",PurchaseAmount,str_LaJolla, PurchaseAmount * tax_LaJolla / 100 );
}
getch();
return 0;
}  

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Sales Tax
7 Sep, 2006 - 07:06 AM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 45 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
The problem is that you are using the wrong format specifier in your scanf statement.

CODE

scanf  ("%d", &PurchaseAmount);


Since PurchaseAmount is of type float you need to use f as a format specifier. d is for integer types.

Should be like this:
CODE

scanf  ("%f", &PurchaseAmount);

User is offlineProfile CardPM
+Quote Post

promiscuoustx
RE: Sales Tax
7 Sep, 2006 - 08:34 AM
Post #7

New D.I.C Head
*

Joined: 30 Aug, 2006
Posts: 36


My Contributions
QUOTE(jayman9 @ 7 Sep, 2006 - 08:06 AM) *

The problem is that you are using the wrong format specifier in your scanf statement.

CODE

scanf  ("%d", &PurchaseAmount);


Since PurchaseAmount is of type float you need to use f as a format specifier. d is for integer types.

Should be like this:
CODE

scanf  ("%f", &PurchaseAmount);



Tks!! Got that fixed, now I am trying to make it to where the total is calculated...maybe you can see
where I am messing up.....
CODE

#include <stdlib.h>
#include <stdio.h>

int main()
{

/*Some food items and all non-food items are subject to a statewide sales tax and local*/
/*district taxes.  Due to differences in district taxes, each store uses a different tax rate*/

      int iResponse = 0;
      float PurchaseAmount;
      float TotalAmt;
      char str_DelMar[] = "Del Mar", str_Encinitas[] = "Encinitas", str_LaJolla[] = "La Jolla";
      /*The above is the three districts*/
      double tax_DelMar = 7.25, tax_Encinitas = 7.5, tax_LaJolla = 7.75;
      /*The above is the distinct district taxes for the three districts*/
      char s;
      char mychar;
      

/*This is to ensure the user of this program knows what the purpose of this program is*/
printf("\nThis is a program to calculate the taxes on articles\n");
printf("\npurchased at a price the user chooses, depending on the district.\n");

/*The user needs to choose which option they want*/
printf("\nFor the district Del Mar, please press 1.\n");
printf("\nFor the district Encinitas, please press 2.\n");
printf("\nFor the district La Jolla, please press 3.\n");
/*Added the option to exit for users*/
printf("\nTo exit, please press 0.\n");
scanf ("%d", &iResponse);
/*Once the user chooses the district, the user must input the dollar amount of the purchase*/
printf("\nPlease enter the purchase amount.\n");
scanf  ("%f", &PurchaseAmount);



if (iResponse == 1){
   printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f, for a total of $%.2f\n",PurchaseAmount,str_DelMar, PurchaseAmount * tax_DelMar / 100, TotalAmt, str_DelMar, PurchaseAmount + tax_DelMar);
}
else {

      if (iResponse == 2)
      printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f for a total of $%.2f\n ",PurchaseAmount,str_Encinitas, PurchaseAmount * tax_Encinitas / 100, TotalAmt,str_Encinitas, PurchaseAmount + tax_Encinitas);
else

        if (iResponse == 3)
        printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f for a total of $%.2f\n ",PurchaseAmount,str_LaJolla, PurchaseAmount * tax_LaJolla / 100, TotalAmt,str_LaJolla, PurchaseAmount +  tax_LaJolla);
}
getch();
return 0;
}  


This post has been edited by promiscuoustx: 9 Sep, 2006 - 01:16 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Sales Tax
7 Sep, 2006 - 10:22 AM
Post #8

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 45 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You have more variables than you have format specifiers and they don't match with the correct specifier.

I think this is what you were trying for:
CODE

if (iResponse == 1){
   printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f, for a total of $%.2f\n",PurchaseAmount, str_DelMar, (PurchaseAmount * tax_DelMar / 100), PurchaseAmount + (PurchaseAmount * tax_DelMar / 100));
}
else {

      if (iResponse == 2)
      printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f for a total of $%.2f\n ",PurchaseAmount, str_Encinitas, (PurchaseAmount * tax_Encinitas / 100), PurchaseAmount + (PurchaseAmount * tax_Encinitas / 100));
else

        if (iResponse == 3)
        printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f for a total of $%.2f\n ",PurchaseAmount, str_LaJolla, (PurchaseAmount * tax_LaJolla / 100), PurchaseAmount +  (PurchaseAmount * tax_LaJolla / 100));
}

User is offlineProfile CardPM
+Quote Post

promiscuoustx
RE: Sales Tax
7 Sep, 2006 - 10:31 AM
Post #9

New D.I.C Head
*

Joined: 30 Aug, 2006
Posts: 36


My Contributions
QUOTE(jayman9 @ 7 Sep, 2006 - 11:22 AM) *

You have more variables than you have format specifiers and they don't match with the correct specifier.

I think this is what you were trying for:
CODE

if (iResponse == 1){
   printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f, for a total of $%.2f\n",PurchaseAmount, str_DelMar, (PurchaseAmount * tax_DelMar / 100), PurchaseAmount + (PurchaseAmount * tax_DelMar / 100));
}
else {

      if (iResponse == 2)
      printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f for a total of $%.2f\n ",PurchaseAmount, str_Encinitas, (PurchaseAmount * tax_Encinitas / 100), PurchaseAmount + (PurchaseAmount * tax_Encinitas / 100));
else

        if (iResponse == 3)
        printf("\nThe tax for the purchase at the price of $%.2f in district %s is $ %.2f for a total of $%.2f\n ",PurchaseAmount, str_LaJolla, (PurchaseAmount * tax_LaJolla / 100), PurchaseAmount +  (PurchaseAmount * tax_LaJolla / 100));
}




That was exactly the problem!!! Another quick question tho....do I have to do a loop if I want to be able to calculate all
of the districts sales together?
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Sales Tax
7 Sep, 2006 - 11:32 AM
Post #10

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 45 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Do you mean that your program will continue to run allowing you to enter multiple purchases as opposed to just ending after executing one time?

If so, then yes you will need a loop.
User is offlineProfile CardPM
+Quote Post

promiscuoustx
RE: Sales Tax
7 Sep, 2006 - 01:21 PM
Post #11

New D.I.C Head
*

Joined: 30 Aug, 2006
Posts: 36


My Contributions
QUOTE(jayman9 @ 7 Sep, 2006 - 12:32 PM) *

Do you mean that your program will continue to run allowing you to enter multiple purchases as opposed to just ending after executing one time?

If so, then yes you will need a loop.


I will work on it tonight and see if I can figure out how to create a loop for it. I may have more
questions tomorrow!!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:08AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month