473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

calculate saletax price

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
  1. int main ()
  2. {
  3. /* variable definition: */
  4. float price, salestax, setprice;
  5. /* Prompt user for price */
  6. printf("Enter the price in dollars: \n");
  7. // Input the price
  8. scanf("$%f", &price);
  9. /* Prompt user for salestax */
  10. printf("Enter the state sales tax: \n");
  11. // Input the salestax
  12. scanf("%f", &salestax);
  13. // Calculate the setprice
  14. setprice = price + (price * salestax);
  15. // Print the result
  16. printf("price with Tax is: $%f\n", &price);
  17. return 0;
  18. }
Mar 11 '16 #1
4 1861
donbock
2,426 Expert 2GB
On line 16, replace &price with price.
By the way, the price with tax is setprice not price.
Mar 11 '16 #2
Thanks,

How would I write that line so it outputs the setprice?
Mar 11 '16 #3
this is what I did.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main ()
  4. {
  5. /* variable definition: */
  6. float price, salestax, setprice;
  7. /* Prompt user for price */
  8. printf("Enter the price in dollars: \n");
  9. // Input the price
  10. scanf("$%f", &price);
  11. /* Prompt user for salestax */
  12. printf("Enter the state sales tax: \n");
  13. // Input the salestax
  14. scanf("%f", &salestax);
  15. // Calculate the setprice
  16. setprice = price + (price * salestax);
  17. scanf("$%f", &setprice);
  18. // Print the result
  19. printf("price with Tax is: $%f\n", setprice);
  20. return 0;
  21. }
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
donbock
2,426 Expert 2GB
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

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a...
1
by: Don Leverton | last post by:
Hi Folks, I *can* calculate the Gross Profit Percentage where both the Cost and SellPrice are known, using the formula: (SellPrice - Cost) / SellPrice = GPP eg ($24.92 - $14.95) / $24.92 =...
1
by: Ladislau S. | last post by:
Dear reader, I am an occasional user of MS Access 2000 running on Windows 98. My hobby is ship model building so I made a database for things that I want to buy. After two strokes I bin unable...
6
by: luanhoxung | last post by:
dear all!! i met the headache problem in setting value for some controls in my form. i have 2 combo box in form F1. i want to set value for some textbox in F1 when i choose value from 2 combo...
7
by: jamesnkk | last post by:
Hi, Although this question may not directly link to Access, but I think it a common question to those developer.so hope you could suggest a solution. How do I get the average cost for Item sold,...
5
by: zivon | last post by:
Hello everyone ! I made a price calculator for a guest house. I have diffrent sale campaigns, all the time, I made a table with campaign name and discount, for example: name "pensioners"...
2
by: scentedstars | last post by:
I had this funtion working by using the onsumbit, but now I have to change it so that it will display the total price after changing the quanity amount. Simple I know, but right now i can not get...
1
by: venkatn | last post by:
Hi, I just starting learning javascript by myself and have quick question if anyone can help. I already checked recent post and couldn't find any similar one. To get value of different check boxes...
1
by: depasqualen | last post by:
I'm trying to make a python program that 1) prompts the user to enter the value of the sale with the following statement: “Enter the value of the company’s sales in dollars in August 2013:” ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.