in my switch program keeps reading wrong input also i know i used way too much fflush(stdin); because stupid printf keeps inputting to the screen so scanf gets bad but i m sure i desinged program nice i dunno why when i like enter num 5 it keeps reading artichokes even though i made the default break;
#include <stdio.h>
//everything here is per pound ofcourse
#define artichokes 1
#define beets 2
#define carrots 3
int ParseFees(int dollars,int type)
{
char shipping;
int pounds=dollars;
dollars*=type;//to get dollar amount
fputs("do you want the stuff shipped ?:_\n",stdout);
fflush(stdin);
shipping=getchar();
toupper(shipping);
if(shipping=='Y') {
if(type==1)
dollars=(dollars + 8) + (type * 2);
switch(pounds) {
case 5:
dollars+=3;
break;
case 10:
dollars+=10;
break;
}
}
return dollars;
}
int main(void)
{
int groc;//variable used for gocery
int pounds;
int dollars=0;
for(;;) {
puts("Hello Sir May I help you with gocery?\n"
"Here is the Menu\n"
"1)artichokes for $1 per pound\n"
"2)beets for 2 $ per pound\n"
"3)carrots for 3 $ per pound\n"
"\nNotice: We give 5 % discount for orders over 100 $\n"
"\n2nd Notice: enter other value to quit the programe and know how many dollars you owe\n"
);
switch(scanf("%d",&groc)) {
case 1:
fputs("how many pounds you want? of artichokes",stdout);
fflush(stdin);
scanf("%d",£s);
dollars+=ParseFees(pounds,artichokes);//rest of here will handle groceries etc
continue;
case 2:
fputs("how many pounds you want? of artichokes",stdout);
fflush(stdin);
scanf("%d",£s);
dollars+=ParseFees(pounds,artichokes);//rest of here will handle groceries etc
continue;
case 3:
fputs("how many pounds you want? of artichokes",stdout);
fflush(stdin);
scanf("%d",£s);
dollars+=ParseFees(pounds,artichokes);//rest of here will handle groceries etc
continue;
default:
puts("thanks for shopping Please visit us again\n");
break;
}
break;
}
if(dollars>100) {
int temp=dollars;
printf("Please Pay %d sir $",(temp/100) * 5 - dollars);
}
else
printf("you owe us %d $",dollars);
fflush(stdin);
getchar();
return 0;
}