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);
}