Hi,

I'm learning C++ programming and have to write a program that shows how to calculate tax rates for a business tha th as shops in 3 different cities with three different tax rates, using the printf function. Anyhelp I can get is appreciated. Keep in mind I am just learning programming for the 1st time. Thanks in advance.

show us what you have done and where you are get your problem and you will get some help

Hi,

I'm learning C++ programming and have to write a program that shows how to calculate tax rates for a business tha th as shops in 3 different cities with three different tax rates, using the printf function. Anyhelp I can get is appreciated. Keep in mind I am just learning programming for the 1st time. Thanks in advance.

Have you used functions yet? I'd start out by deciding what the input and output will be (i.e. do you read from an input file? Does the user enter data? How should the data be outputted to the screen?) Write the input and output functions and get them to work. I don't know what you mean by "calculate tax rates". Do you mean "calculate taxes FROM tax rates"? Also, you can use printf in C++, but generally people use cout. printf is normally used in C. Any reason you are using it instead of cout?

Iput your code so far and what it says error wise if it doesnt compile , so we can see where you have gone wrong and point you the right way.
I have a similar program but , would like to see what you have done?

Here's what I have so far

#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 iSelection=0;
      float fTransAmount = 125.00;
      float fTotalSale = 0.00;     
      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 district taxes for the three districts*/
    
      float runningTotalTax1;
      float runningTotalTax2;
      float runningTotalTax3;
        /*User to select option*/
  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
            
 
  if (iResponse == 1)
  scanf  ("%f", &$125);
  {
 The tax for the purchase at the price of $%.TransAmountf in district %s is $%.2f, for a total of $%.2f\n",Transamount,str_DelMar, ($Transamount * tax_DelMar / 100), 
   runningTotal1 = runningTotalTax1 +$TransAmount;
            
  }
  else 
  if (iResponse == 2)
  {
  
   scanf  ("%f", &$125);
   printf("\nThe tax for the purchase at the price of $%.2f in district %s is $%.2f for a total of $%.2f\n ",TransAmount,str_Encinitas, ($TransAmount * tax_Encinitas / 100), TransAmount + (TransAmount * tax_Encinitas / 100));
  runningTotalTax2 = runningTotalTax2 + TransAmount;
        }
  
  else 
  if (iResponse == 3)
  {
  
   scanf  ("%f", &TransAmount);
   printf("\nThe tax for the purchase at the price of $%.2f in district %s is $%.2f for a total of $%.2f\n ",TransAmount,str_LaJolla, (TransAmount * tax_LaJolla / 100), TransAmount +  (TransAmount * tax_LaJolla / 100));
  runningTotalTax3 = runningTotalTax3 + TransAmount;
        } //end if
}//end main function

I have just started learning to write code so your patience is appreciated. The printf function.I think they are teaching us to do C Programming first.

Hi,

I'm learning C++ programming and have to write a program that shows how to calculate tax rates for a business tha th as shops in 3 different cities with three different tax rates, using the printf function. Anyhelp I can get is appreciated. Keep in mind I am just learning programming for the 1st time. Thanks in advance.

That's rather odd -- c++ classes normally do not teach C functions such as printf(). All the code you posted is C, not C++.

#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 iSelection=0;
	float fTransAmount = 125.00;
	float fTotalSale = 0.00;
	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 district taxes for the three districts*/

	float runningTotalTax1;
	float runningTotalTax2;
	float runningTotalTax3;
	/*User to select option*/
	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


		if (iResponse == 1)
			scanf ("%f", &$125);
	{
		The tax for the purchase at the price of $%.TransAmountf in district %s is $%.2f, for a total of $%.2f\n",Transamount,str_DelMar, ($Transamount * tax_DelMar / 100),
			runningTotal1 = runningTotalTax1 +$TransAmount;

	}
		else
			if (iResponse == 2)
			{

				scanf ("%f", &$125);
				printf("\nThe tax for the purchase at the price of $%.2f in district %s is $%.2f for a total of $%.2f\n ",TransAmount,str_Encinitas, ($TransAmount * tax_Encinitas / 100), TransAmount + (TransAmount * tax_Encinitas / 100));
				runningTotalTax2 = runningTotalTax2 + TransAmount;
			}

			else
				if (iResponse == 3)
				{

					scanf ("%f", &TransAmount);
					printf("\nThe tax for the purchase at the price of $%.2f in district %s is $%.2f for a total of $%.2f\n ",TransAmount,str_LaJolla, (TransAmount * tax_LaJolla / 100), TransAmount + (TransAmount * tax_LaJolla / 100));
					runningTotalTax3 = runningTotalTax3 + TransAmount;
				} //end if
}//end main function

Line 24 - You're missing an ending parentheses.
Line 24 - iResponse is never declared.
Line 30 - I assume you want a printf statement here?
Lines 28 and 38 - My scanf syntax is very rusty but these look odd. Why do you have 125 in these statements? Shouldn't these be variable addresses instead?
Line 39 and others: What's TransAmount? Do you mean fTransAmount?

Lines 30 and 31 - Why is the $ in front of TransAmount? Also, watch your capitalization. Variable names are case sensitive.

That's rather odd -- c++ classes normally do not teach C functions such as printf(). All the code you posted is C, not C++.

I don't think that's such a bad idea to teach C first. C in itself is actually a simpler language than C++, and it's the underlying language of C++ (and most modern languages these days), so it makes sense to learn it first. Although I do have to admit that the solutions created with C do tend to be lengthier than their C++ counterparts (in most cases).

Perhaps this thread might be better suited to the C forum?

Yes John I agree, but the OP clearly stated he is supposed to be learning c++, not C. Unless he is confused about what exactly it is that he is learning.

Moved to C board.

This article has been dead for over six months. Start a new discussion instead.