• 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;
}
``````
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author 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;
}
``````
0
Commented:
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
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.