早教吧作业答案频道 -->其他-->
关于continue的用法疑问://animal.c#include#includeintmain(void){charch;printf("Givemealetterofthealphabet,andiwillgive");printf("ananimalname\nbeginningwiththatletter.\n");printf("Pleasetypeinaletter:type#toend
题目详情
关于continue的用法疑问:
// animal.c
#include
#include
int main(void)
{
char ch;
printf(" Give me a letter of the alphabet,and i will give ");
printf(" an animal name \n beginning with that letter.\n");
printf("Please type in a letter :type # to end my act.\n");
while((ch= getchar()) = '#');
{
if('\n'==ch)
continue;
if(islower(ch))
switch(ch)
{
case 'a':
printf("argali,awild sheep of Asia\n");
break;
case 'b':
printf("bablirusa,a wild pig of Malay \n");
break;
case 'c':
printf("coati,racoonlike mammal \n");
break;
case 'd':
printf("Desman,aquatic,molelike critter \n");
break;
case 'e':
printf("echidna,the spiny anteater\n");
break;
case'f':
printf("fisher,brownish marten \n");
break;
default:
printf("That's a stumper \n");
}
else
printf("I recognize only lowercase letters.\n");
while(getchar()!='\n')
continue;
printf("Please enter another letter of a #.\n");
}
printf("Bye!\n");
return 0;
}
编译了一下,发现有问题:
错误提示是:
--------------------Configuration:animal2 - Win32 Debug--------------------
Compiling...
animal2.c
D:\我的文档\animal2.c(13) :error C2044:illegal continue
Error executing cl.exe.
animal2.obj - 1 error(s),0 warning(s)
// animal.c
#include
#include
int main(void)
{
char ch;
printf(" Give me a letter of the alphabet,and i will give ");
printf(" an animal name \n beginning with that letter.\n");
printf("Please type in a letter :type # to end my act.\n");
while((ch= getchar()) = '#');
{
if('\n'==ch)
continue;
if(islower(ch))
switch(ch)
{
case 'a':
printf("argali,awild sheep of Asia\n");
break;
case 'b':
printf("bablirusa,a wild pig of Malay \n");
break;
case 'c':
printf("coati,racoonlike mammal \n");
break;
case 'd':
printf("Desman,aquatic,molelike critter \n");
break;
case 'e':
printf("echidna,the spiny anteater\n");
break;
case'f':
printf("fisher,brownish marten \n");
break;
default:
printf("That's a stumper \n");
}
else
printf("I recognize only lowercase letters.\n");
while(getchar()!='\n')
continue;
printf("Please enter another letter of a #.\n");
}
printf("Bye!\n");
return 0;
}
编译了一下,发现有问题:
错误提示是:
--------------------Configuration:animal2 - Win32 Debug--------------------
Compiling...
animal2.c
D:\我的文档\animal2.c(13) :error C2044:illegal continue
Error executing cl.exe.
animal2.obj - 1 error(s),0 warning(s)
▼优质解答
答案和解析
你的while后面有个分号.后面那个大括号就不在while里了,所以continue也不再while里,continue只有在循环内才有意义,否则就会出现这种错误.
看了 关于continue的用法疑...的网友还看了以下:
已知单项式2x^my^n+2与3x^m+2y^4-n的次数相同,求n的值?读法:2乘x的m次方乘y的 2020-03-31 …
关于牛顿迭代法的有关问题,高手请进啊!!在牛顿迭代法运用在mathematica中,函数根的n+1 2020-04-12 …
数据结构时间复杂度问题一个算法所需时间由以下递归算法表示,试求出该算法的时间复杂度的级别当n=1时 2020-05-01 …
用秦九韶算法求n次多项式f(x)=anxn+an-1xn-1+…+a1x+a0,当x=x0时,求f 2020-05-17 …
1/N为什么不是收敛的无穷级数,而1/n^2确是收敛的.根据比值法,1/N+1/1/N=N/N+1 2020-05-20 …
某人在上楼梯时,一步上一个台阶或两个台阶,设他从平地上到第一级台阶时有f(1)种走法,从平地到第二 2020-05-22 …
某算法的时间代价递推关系为T(n)=2T(n/2)+n,T(1)=1,则该算法的时间复杂度为____ 2020-05-26 …
有2×n的一个长方形方格,用一个1×2的骨牌铺满方格.例如n=3时,为2×3方格.①当n=4时,有 2020-06-04 …
C++习题法师为了战胜妖魔,准备好了可以记为1,2,……,N的N类符咒字法师为了战胜妖魔,准备好了 2020-06-23 …
1.下列算法中,所指满足条件的n是指n为_S1输入nS2判断n是否为2;若n=2,则n满足条件,结 2020-07-04 …