【发布时间】:2021-12-30 05:02:06
【问题描述】:
这是我的代码,每次循环运行时我都会输入 char。
我提供了 5 个输入,但它只响应其中的 2 个。
#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
char c;
scanf("%c",&c);
if(c =='b' || c== 'B')
printf("BattleShip\n");
else if(c=='c' || c=='C')
printf("Cruiser\n");
else if(c == 'd' || c=='D')
printf("Destroyer\n");
else if(c=='f' || c=='F')
printf("Frigate\n");
}
}
Input:
5
b f c b f
Output:
BattleShip
Frigate
【问题讨论】:
-
您在
c中收到的输入是什么?输出它的整数值(printf("%d\n", (int)c);),只是为了避免看不到空格或换行符的问题。顺便说一句,作为这里的新用户,也请带上tour 并阅读How to Ask(尽管您的问题没有有典型的初学者错误)。