# Thread: How can I enter item price?

1. ## How can I enter item price?

Hi,

I've managed to write the following program that displays total purchase price amounts for places with different sales tax rates. As it is, it assumes a value of \$125, but I need to now modify it so a user can input any item price. I'm banging my head against a wall with this one.

Thanks for any help!

Code:
```#include <stdio.h>
main()
{
char city1[] = "Lajolla";
char city2[] = "Encintas";
char city3[] = "Delmar";
float tax1;
float tax2;
float tax3;
int pur1;
tax1 =7.75;
tax2 =7.5;
tax3 =7.25;
pur1 =125;
printf("\nItem price is %d\n", pur1);
getch();
printf("Tax at %s is: \$%.2f\n", city1,pur1 * (tax1 / 100) );
printf("Tax at %s is: \$%.2f\n", city2,pur1 * (tax2 / 100) );
printf("Tax at %s is: \$%.2f\n", city3,pur1 * (tax3 / 100) );
getch();
}```

2. Read up on scanf, and make main return int.

3. Eg.
Code:
```int x;
scanf("%d%*c",&x);```
The red part makes sure the newline at the end of the input is discarded, since what you enter is

56\n

'\n' being the product of the enter key.

Do not use floating point numbers for money, read this:

http://cboard.cprogramming.com/c-pro...tml#post882468

My trick for printing dollars and cents there needs a slight tweak tho:
Code:
```int x=500;
printf("\$%d.%02d\n",x/100,x%100);```
The "0" will fill in the two digit placeholder with zeros, so you get "\$5.00" and not "\$5. 0".

4. Also make sure that you use indentation in the code that you write. It looks neat and readable.