?
Solved

Kudler Tax Calculator Homework C Language Problems

Posted on 2008-11-11
3
Medium Priority
?
1,596 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:shawnswearengin
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 22934567
>>         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
 

Author Comment

by:shawnswearengin
ID: 22936800
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 22937463
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question