• C

Kudler Tax Calculator Homework C Language Problems

I am trying to get this code to work properly using the Miracle C Compiler.  It builds, compiles, and executes.  Then it asks for me to enter the price and I enter the purchase price then it prints but it doesn't ever calculate.

Thanks
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
  
/*Using define macros for assigning tax to different stores */
float taxes=0.0;
float price=0.0;
float delmartaxrate=0.0725;
float encinitastaxrate=0.075;
float lajollataxrate=0.075;
float value=0.0;
char storelocation;	 
	printf("Kudler Fine Foods Tax Calculator\n"); 
	printf("Enter Price\n");
	scanf("%s", value);
	
	 for(;;)
	{
		printf("Choose Store Location\n");
		printf("1) DelMar \n2) Encinitas \n3) La Jolla \nQ) Quit\n");
		printf("Select 1, 2, 3 or Q: "); 
		scanf("%c",&storelocation);
		fgetc(stdin); 
		printf("%c",&storelocation);
		if (storelocation == '1')
		{
			taxes = value * delmartaxrate;
			price = value + taxes;
			printf("Store Name: DelMar \nTax Rate: ");
			printf("7.25");
			printf("\nPurchase Price: ");
			printf("%d", value);
			printf("\nTaxes Price: "); 
			printf("%d", taxes);
			printf("\nTotal Purchase Price: "); 
			printf("%d", price);
			printf("\n");
		}
		else if (storelocation == '2')
		{
			taxes = price * encinitastaxrate;
			price = price + taxes;
			printf("Store Name: Encinitas \nTax Rate: ");
			printf("%f", "7.5");
			printf("\nPurchase Price: ");
			printf("%d", price);
			printf("\nTaxes Price: "); 
			printf("%d", taxes);			
			printf("\nTotal Purchase Price: "); 
			printf("%d", price);
			printf("\n");
		}
		else if (storelocation == '3')
		{
			taxes = price * lajollataxrate;
			price = price + taxes;
			printf("Store Name: LaJolla \nTax Rate: ");
			printf("%f", "7.75");
			printf("\nPurchase Price: ");
			printf("%d", price);
			printf("\nTax Price: "); 
			printf("%d", taxes);
			printf("\nTotal Purchase Price: "); 
			printf("%d", price);
			printf("\n");
		}
		else if (storelocation == 'Q')
		{
			break;
		}
		else 
		{
			printf("Entry not acceptable, please choose another selection.");
		}	
	}
 
	return 0;
}

Open in new window

shawnswearenginAsked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
>>         scanf("%s", value);

value is a float, so you use %f (%s is for strings). You also need to pass the address of the variable, so :

        scanf("%f", &value);

        http://www.cplusplus.com/reference/clibrary/cstdio/scanf.html


>>                 printf("%c",&storelocation);

For printf's you pass the value itself, not the address, so :

        printf("%c", storelocation);
0
 
shawnswearenginAuthor Commented:
I made those changes and I still get the same results.  It shows the tax rate for the city but never calculates any of the formulas to multiply taxes by price and then add them together to show total price.
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
  
/*Using define macros for assigning tax to different stores */
float taxes=0.0;
float price=0.0;
float delmartaxrate=0.0725;
float encinitastaxrate=0.075;
float lajollataxrate=0.075;
float value=0.0;
char storelocation;	 
	printf("Kudler Fine Foods Tax Calculator\n"); 
	printf("Enter Price\n");
	scanf("%f", &value);
	
	 for(;;)
	{
		printf("Choose Store Location\n");
		printf("1) DelMar \n2) Encinitas \n3) La Jolla \nQ) Quit\n");
		printf("Select 1, 2, 3 or Q: "); 
		scanf("%c", &storelocation);
		fgetc(stdin); 
		printf("%c", storelocation);
		if (storelocation == '1')
		{
			taxes = value * delmartaxrate;
			price = value + taxes;
			printf("Store Name: DelMar \nTax Rate: ");
			printf("7.25");
			printf("\nPurchase Price: ");
			printf("%d", value);
			printf("\nTaxes Price: "); 
			printf("%d", taxes);
			printf("\nTotal Purchase Price: "); 
			printf("%d", price);
			printf("\n");
		}
		else if (storelocation == '2')
		{
			taxes = price * encinitastaxrate;
			price = price + taxes;
			printf("Store Name: Encinitas \nTax Rate: ");
			printf("%f", "7.5");
			printf("\nPurchase Price: ");
			printf("%d", price);
			printf("\nTaxes Price: "); 
			printf("%d", taxes);			
			printf("\nTotal Purchase Price: "); 
			printf("%d", price);
			printf("\n");
		}
		else if (storelocation == '3')
		{
			taxes = price * lajollataxrate;
			price = price + taxes;
			printf("Store Name: LaJolla \nTax Rate: ");
			printf("%f", "7.75");
			printf("\nPurchase Price: ");
			printf("%d", price);
			printf("\nTax Price: "); 
			printf("%d", taxes);
			printf("\nTotal Purchase Price: "); 
			printf("%d", price);
			printf("\n");
		}
		else if (storelocation == 'Q')
		{
			break;
		}
		else 
		{
			printf("Entry not acceptable, please choose another selection.");
		}	
	}
 
	return 0;
} 

Open in new window

0
 
Infinity08Commented:
When you output float's, you also have to use %f's (not %d's).

Something like this :

>>                         printf("%f", "7.5");

doesn't work either. %f is for float's, remember ? "7.5" is a string, not a float. Take a look at the reference page for printf :

        http://www.cplusplus.com/reference/clibrary/cstdio/printf.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.