int sc1,sc2,a=0,b=0;
do
{
printf("Give the scores\n");
scanf("%d %d", &sc1,&sc2);
//===============================================
if (sc1 > sc2)
a+=1;
else if (sc1<sc2)
b+=1;
else if (sc1==sc2)
printf("tie\n");
//===============================================
if (a>b)
printf("team 1 is in the lead\n");
else if (a<b)
printf("team 2 is in the lead\n");
else if (b==a)
printf("tie\n");
}
while((a==3) || (b==3));
//===============================================
if (a==3)
printf("team 1 got the cup");
else
printf("team 2 got the cup");
我想我写错了什么。我已经搜索了很多次,但似乎找不到哪里出了问题。
(两支球队中的一支可以赢得奖杯,这支球队必须有3场胜利)
*else if(sc1
*else if(a>b)
发布于 2011-05-01 19:44:46
如果我正确地理解了您的问题,您希望终止条件是其中一个团队"a“或"b”的得分为3。但是,在您的代码中,您已经编写了while循环的唯一方式是如果其中一个团队的得分为3。您希望:
while( !( a==3 || b == 3) )
发布于 2011-05-01 19:45:29
while((a==3) || (b==3));
仅当a
或b
为3时才会循环。如果您想要等到其中一个是3,则使用:
while ((a!=3) && (b!=3));
发布于 2011-05-01 19:46:00
您的循环条件不正确。它提前停止,因为两个队的得分都不是3。循环,直到其中一个达到3:
while((a < 3) && (b < 3));
https://stackoverflow.com/questions/5850847
复制相似问题