Solved

# Kudler Tax Calculator Homework C Language Problems

Posted on 2008-11-11
1,561 Views
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;

}
``````
0
Question by:shawnswearengin

LVL 53

Accepted Solution

>>         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

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

LVL 53

Expert Comment

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

### Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.