# Need help to show decimals

• 02-19-2008
engstudent363
Need help to show decimals
I know that I use "float" but where do I place the word float so that my program output shows decimals. Right now the program just cuts the decimals off. This program stores how many of each product you choose to purchase and calculates the total amount paid with tax. The tax is .18 but it's showing only integers, no decimals. Please help me by telling me where to place the word "float" within my program.

Here's the program:
Code:

```#include <stdio.h>         main () {         int counter,city,shop,i,menu,taxtotal,amounttotal,l,j,k;         int breadtotal=0;         int diapertotal=0;         int beertotal=0;                 counter=6;         shop=1;         city=1;         for (counter>0;counter--;) {         printf("You are at City # %d and Shop # %d\nPlease enter your product choice\n1 --> Beer\n2 --> Diaper\n3 --> Bread\n0 --> Nothing\n",city,shop);                 shop=shop+1;                 if (shop==4) {         city=2;         shop=1;         }         scanf("%d", &menu);                         switch (menu) {                 case 1:                 beertotal=beertotal + 1;                 break;                 case 2:                 diapertotal=diapertotal + 1;                 break;                 case 3:                 breadtotal=breadtotal + 1;                 break;                 default: printf("Nothing purchased.\n");                 }                                 }                 l=beertotal*10;         j=diapertotal*5;         k=breadtotal*2;         taxtotal=(l+j+k)*.18;         amounttotal=l+j+k+taxtotal;         printf("Thank you for shopping with us.\nShopping Summary:\n%d Beer, %d Diapers, %d Bread\nTax paid: \$%d\nTotal Amount: \$%d\n",beertotal,diapertotal,breadtotal,taxtotal,amounttotal);         }```
• 02-19-2008
ulillillia
Float is just another variable type. You use it just like int and char. When displaying it, you need &#37;f. To specify the number of decimal places you want, use %.4f for four decimal places. There's also exponential form, but I haven't used that yet.
• 02-19-2008
vart
probably you want something like this
Code:

```int main() {   float a = 0.5;   double b = 1.23;   printf("A=&#37;.2f, B= %.2f",a,b);   return 0; }```
Note that main should be declared as int explicetaly
• 02-19-2008
tabstop
If you want taxtotal to be a float, make it so: float taxtotal; instead of int taxtotal; at the top. Same with amounttotal.
You also have to print floats using (I would suggest in this case) %.2f.
• 02-19-2008
engstudent363
thank you sirs