【求助】新手问题
目的是进行一次操作后用while循环还能进行操作一共进行times次
但编译结果和预期不一样啊
#include <stdio.h>
int main()
{
int a, F, count = 0, times, count1 = 0;
printf("请输入操作次数\n");
scanf("%d", ×);
while (count1 < times)
{
count1 = count1 + 1;
printf("请输入操作类型和操作程度\n");
scanf("%c %d", &a, &F);
switch(a)
{
case 'L' :
while (count < F)
{
count = count + 1;
printf("向左转");
}
break;
case 'R' :
while (count < F)
{
count = count + 1;
printf("向右转");
}
break;
case 'G' :
while (count < F)
{
count = count + 1;
printf("前进");
}
break;
case 'B' :
while (count < F)
{
count = count + 1;
printf("后退");
}
break;
}
}
return 0;
}
加了个default
#include <stdio.h>
int main()
{
int a, F, count = 0, times, count1 = 0;
printf("请输入操作次数\n");
scanf("%d", ×);
while (count1 < times)
{
count1 = count1 + 1;
printf("请输入操作类型和操作程度\n");
scanf("%c %d", &a, &F);
switch(a)
{
case 'L' :
while (count < F)
{
count = count + 1;
printf("向左转");
}
break;
case 'R' :
while (count < F)
{
count = count + 1;
printf("向右转");
}
break;
case 'G' :
while (count < F)
{
count = count + 1;
printf("前进");
}
break;
case 'B' :
while (count < F)
{
count = count + 1;
printf("后退");
}
break;
default:
continue;
}
}
return 0;
}
页:
[1]