从For循环获取Switch语句 #包括 国际一方; 字符x=''; 浮动总计=0,perCost=0; main(){ 开关(顶部(x)){ 案例“A”: printf(“组合A:朋友鸡配沙拉[价格:4.25]”); perCost=4.24; 打破 案例“B”: printf(“组合B:烤牛肉加土豆泥[价格:5.75]”); perCost=5.75; 打破 案例“C”: printf(“组合A:鱼和薯条[价格:5.25]”); perCost=5.25; 打破 案例“D”: printf(“套餐A:汤和沙拉[价格:3.74]”); perCost=3.75; 打破 违约: perCost=0; 打破 } printf(“输入参与方总数:”); scanf(“%d”和第三方); 对于(i=0;i
是什么导致我的编程无法从switch语句中获取信息?我认为您的switch语句需要在循环中:从For循环获取Switch语句 #包括 国际一方; 字符x=''; 浮动总计=0,perCost=0; main(){ 开关(顶部(x)){ 案例“A”: printf(“组合A:朋友鸡配沙拉[价格:4.25]”); perCost=4.24; 打破 案例“B”: printf(“组合B:烤牛肉加土豆泥[价格:5.75]”); perCost=5.75; 打破 案例“C”: printf(“组合A:鱼和薯条[价格:5.25]”); perCost=5.25; 打破 案例“D”: printf(“套餐A:汤和沙拉[价格:3.74]”); perCost=3.75; 打破 违约: perCost=0; 打破 } printf(“输入参与方总数:”); scanf(“%d”和第三方); 对于(i=0;i,c,for-loop,switch-statement,C,For Loop,Switch Statement,是什么导致我的编程无法从switch语句中获取信息?我认为您的switch语句需要在循环中: #include <stdio.h> int i, party; char x = ' '; float total = 0, perCost = 0; main(){ switch (toupper(x)) { case 'A': printf("Combo A: Friend Chicke
#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);
}
for(i=0;i
我认为您的switch语句需要在循环中:
#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);
}
for(i=0;i
因为您的switch语句顺序错误。。。它需要在扫描后的循环内
更重要的是,我认为你混淆了两件事。1) 需要显示的内容和2)需要处理的内容。。。试试这个:
for (i = 0; i < party; i++) {
printf("Enter item ordered [A/B/C/D/X]: ");
scanf("%c%*c", &x);
// Put your switch here.
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;
}
total = total + perCost; // Move this into the loop.
}
#包括
使用名称空间std;
int main(){
国际一方;
字符x='';
浮动总计=0,perCost=0;
printf(“输入参与方总数:”);
scanf(“%d”和第三方);
printf(“组合A:朋友鸡配沙拉[价格:4.25]”);
printf(“组合B:烤牛肉加土豆泥[价格:5.75]”);
printf(“组合A:鱼和薯条[价格:5.25]”);
printf(“套餐A:汤和沙拉[价格:3.74]”);
对于(i=0;i
因为您的switch语句顺序错误。。。它需要在扫描后的循环内
更重要的是,我认为你混淆了两件事。1) 需要显示的内容和2)需要处理的内容。。。试试这个:
for (i = 0; i < party; i++) {
printf("Enter item ordered [A/B/C/D/X]: ");
scanf("%c%*c", &x);
// Put your switch here.
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;
}
total = total + perCost; // Move this into the loop.
}
#包括
使用名称空间std;
int main(){
国际一方;
字符x='';
浮动总计=0,perCost=0;
printf(“输入参与方总数:”);
scanf(“%d”和第三方);
printf(“组合A:朋友鸡配沙拉[价格:4.25]”);
printf(“组合B:烤牛肉加土豆泥[价格:5.75]”);
printf(“组合A:鱼和薯条[价格:5.25]”);
printf(“套餐A:汤和沙拉[价格:3.74]”);
对于(i=0;i
它看起来不像你