【发布时间】:2011-10-26 03:31:39
【问题描述】:
#include <stdio.h>
int i, party;
char x = ' ';
float total = 0, perCost = 0;
main(){
switch (toupper(x)) {
case 'A':
printf("Combo A: Friend Chicken with slaw [price: 4.25]");
perCost = 4.24;
break;
case 'B':
printf("Combo B: Roast beef with mashed potato [price: 5.75]");
perCost = 5.75;
break;
case 'C':
printf("Combo A: Fish and chips [price: 5.25]");
perCost = 5.25;
break;
case 'D':
printf("Combo A: soup and salad [price: 3.74]");
perCost = 3.75;
break;
default:
perCost = 0;
break;
}
printf("Enter Party Total: ");
scanf("%d", &party);
for (i = 0; i < party; i++) {
printf("Enter item ordered [A/B/C/D/X]: ");
scanf("%c%*c", &x);
}
total = total + perCost;
printf("%f\n", total);
}
是什么导致我的程序无法从 switch 语句中抓取?
【问题讨论】:
-
这是 C,无论您如何看待它,即使您包含 C++ 标头。重新标记并编辑了标题。
标签: c for-loop switch-statement