2020-10-10 11:28

# c语言if语句不能正常运行？

else，然后直接结束了。但是单独把问题三拿出来运行是没有问题的。请各位大神帮我看一下是那里写错了呢？谢谢各位大佬。

``````#include<stdio.h>

int main()

{
char one_sport;
int two_people;
int two_priceA;
int two_priceB;
int two_priceC;
char three_sort;
int three_quantity;
int three_aq;
int three_bq;
int three_cq;
double priceA;
double priceB;
double priceC;

//problem 1
printf("Problem 1\n");
printf("Enter w for walk and s for swim\n");
scanf("%c",&one_sport);

if(one_sport == 'w')
{
printf("You need to walk 15.2 hours to burn off a pound\n");
}
else
{
printf("You need to swim 8.75 hours to burn off a pound\n");
}

//problem 2
printf("problem 2\n");
scanf("%d",&two_people);
two_priceA = two_people * 15;
two_priceB = two_people * 12;
two_priceC = two_people * 10;
if(two_people >=1&&two_people<=8 )
{
printf("Total cost for your group is %d\n",two_priceA);
}

else if(two_people >=9&&two_people<=15)
{
printf("Total cost for your group is %d\n",two_priceB);
}

else
{
printf("Total cost for your group is %d\n",two_priceC);
}

//problem 3

printf("problem 3\n");
printf("Enter A if you want to purchase a shirt,a B if you want to purchase a hat,\nand C if you want to enter a poster.\n");

scanf("%c",&three_sort);

switch(three_sort)
{

}

if(three_sort =='A')
{

scanf("%d",&three_aq);
priceA = three_aq * 10;
printf("You owe \$%.2lf\n",priceA);

}
else if(three_sort =='B')
{

scanf("%d",&three_bq);
priceB = three_bq * 20;
printf("You owe \$%.2lf\n",priceB);

}
else if(three_sort =='C')
{

scanf("%d",&three_cq);
priceC = three_cq * 30;
printf("You owe \$%.2lf\n",priceC);

}

else
{
}
}
``````
• 写回答
• 好问题 提建议
• 追加酬金
• 关注问题
• 邀请回答

#### 1条回答默认 最新

• threenewbee 2020-10-10 12:09
最佳回答

scanf("%c",&three_sort);
的前面加上一个
fflush(stdin);

评论
解决 无用
打赏 举报