hi guys i have a program about counting items and adding their prices and checking if the item is Towel i should start counting coz the costumer must only buy 3 towels.
i got program right but the total always doubled ):
can u help
here's the code
thanx in advance
Code:
#include <stdio.h>
#include <string.h>
char item[20];
int towelnum;
float subtotal, price;
int main() {
towelnum = 0.0;
printf("Enter item then price\n");
printf("Enter XXX to stop\n");
subtotal = 0;
while(true){
gets(item);
if (strcmp(item,"XXX")==0){
break;
}
if (strcmp(item,"Towel")== 0 ){
towelnum++;
}
scanf("%f", &price);
subtotal = subtotal + price;
if(towelnum > 3){
printf("You exceeded\n");
towelnum--;
subtotal = subtotal - price;
}
}
printf("Subtotal: $%1.2f\n", subtotal);
if(towelnum == 3){
printf("Total: $%1.2f", subtotal - 5);
}
else{
printf("Total: $%1.2f", subtotal);
}
}