早教吧作业答案频道 -->其他-->
关于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的用法疑...的网友还看了以下:
已知数列{a}满足a1=a,对任意m,n属于N+,am+n=am*an恒成立1.求通项公式an2. 2020-05-17 …
对于n元素的向量,将其建立为一个有序单链表的时间复杂度为()。A.O(1)B.O(n)C.O(n2) 2020-05-24 …
如图(1),已知圆O是等边△ABC的外接圆,过O点作MN∥BC分别交AB、AC于M、N,且MN=a 2020-05-24 …
n(n》3)边形A1A2A3…An-1An中,∠A1,∠A2的平分线交于点O,∠A3+∠A4+…∠ 2020-07-09 …
1.已知数列{a(n)}满足a(n)a(n+1)a(n+2)a(n+3)=24,且a1=1a2=2 2020-07-09 …
设集合A={(x,y)|x=m,y=3m+1,属于N*}(N*就是1、2、3、4、5等等),B={ 2020-07-30 …
设f(N)、g(N)是定义在正数集上的正函数.如果存在正的常数C和自然数N0,使得当N≥N0时有f 2020-07-31 …
已知一个边长为a的等边三角形,现将其边长n(n为大于2的整数)等分,并以相邻等分点为顶点向外作小等 2020-08-01 …
等边三角形ABC,AB=a,O为三角形的中心,过O点的直线交AB于M,交AC于N,求1.等边三角形 2020-08-03 …
已知数列{an}满足a1=1/2,an+1=an/(e^n*an+e)n属于N*(1)求数列{an} 2021-02-09 …