449,054 Members | 1,320 Online
Need help? Post your question and get tips & solutions from a community of 449,054 IT Pros & Developers. It's quick & easy.

# calculate saletax price

 P: 12 I need to be able to show the output of price in dollars, state tax and price with sales tax, so far I have the following. What am I doing wrong or what have I left out. The code runs but doesn't not show any output. the code: Expand|Select|Wrap|Line Numbers int main () { /* variable definition: */ float price, salestax, setprice; /* Prompt user for price */ printf("Enter the price in dollars: \n"); // Input the price scanf("\$%f", &price); /* Prompt user for salestax */ printf("Enter the state sales tax: \n"); // Input the salestax scanf("%f", &salestax); // Calculate the setprice setprice = price + (price * salestax); // Print the result printf("price with Tax is: \$%f\n", &price); return 0; } Mar 11 '16 #1
4 Replies

 Expert 100+ P: 2,404 On line 16, replace &price with price. By the way, the price with tax is setprice not price. Mar 11 '16 #2

 P: 12 Thanks, How would I write that line so it outputs the setprice? Mar 11 '16 #3

 P: 12 this is what I did. Expand|Select|Wrap|Line Numbers #include    int main () { /* variable definition: */ float price, salestax, setprice; /* Prompt user for price */ printf("Enter the price in dollars: \n"); // Input the price scanf("\$%f", &price); /* Prompt user for salestax */ printf("Enter the state sales tax: \n"); // Input the salestax scanf("%f", &salestax); // Calculate the setprice setprice = price + (price * salestax); scanf("\$%f", &setprice); // Print the result printf("price with Tax is: \$%f\n", setprice); return 0; } my input is this: Price: 19.99 salestax: .06 What I get is: price with Tax is: \$-26.856455 What am I doing wrong? Mar 11 '16 #4

 Expert 100+ P: 2,404 Line 16 calculates setprice, but then line 17 throws away that calculation. I suspect you may not be setting price properly. I suggest you follow each of the line 10 and 14 scanf's with a printf to confirm the value was entered properly. Take a look at the definition of scanf. Notice how the return value tells you how many conversions took place. For lines 10 and 14, the return value should be 1. You should verify this and print an error message if the return value is anything else. Mar 12 '16 #5