C语言程序调试

#include"stdio.h"#include"time.h"#include"stdlib.h"voidmain(){intcomputer,user;charc;... #include "stdio.h"
#include "time.h"
#include "stdlib.h"
void main()
{
int computer,user;
char c;
srand ((unsigned)time(NULL));
printf("Starting!");
printf("Please input 1.Stone,2.Scissor,3.Paper");
scanf("%d",&user);
computer=rand()%3+1;
printf("Computer output is %s\n\n",computer==1?"Stone":computer==2?"Scissor":computer==3?"Paper");
switch (computer-user)
{
case 0:
printf("Draw!\n\n");
break;
case 1:
case -2:
printf("computer win!\n\n");
case -1:
case 2:
printf("You win!\n\n");
}
printf("Continue the game please press Y,press other key will exit");
getchar();
c=getchar();
}
while (c=="y"||c=="Y")
printf("It's all ready exit");
}
有五个错误,但是怎么也找不出来,望高手指点~~
展开
 我来答
shock_m
2011-06-02 · 超过36用户采纳过TA的回答
知道小有建树答主
回答量:140
采纳率:0%
帮助的人:76.3万
展开全部
main函数用int返回值比较好,不过也只是警告;
case 1/-2部分少了break;
缺少do,while上面的花括号没有对应的正括号;
while的判断条件char不能和字符串比较,这是指针和整型比较了,应该用单引号,如果用双引号,则判断会错误;
?:句式有问题,最后一个"paper"少一个:段,最后一个判断其实也没必要,模3得到的整数加1,只能是1/2/3,这个判断是废的。
如果补充了do,那么while后面应增加";"分号结束。

最终语法和逻辑都正确的应该是(当然其实并不够严谨,换行等排版也很难看):
#include "stdio.h"
#include "time.h"
#include "stdlib.h"

int main()
{
int computer,user;
char c;
do
{
srand ((unsigned)time(NULL));
printf("Starting!");
printf("Please input 1.Stone,2.Scissor,3.Paper");
scanf("%d",&user);
computer=rand()%3+1;
printf("Computer output is %s\n\n",computer==1?"Stone":computer==2?"Scissor":computer==3?"Paper":"unknow");
switch (computer-user)
{
case 0:
printf("Draw!\n\n");
break;
case 1:
case -2:
printf("computer win!\n\n");
break;
case -1:
case 2:
printf("You win!\n\n");
}
printf("Continue the game please press Y,press other key will exit");
getchar();
c=getchar();
}
while (c=='y'||c=='Y');

printf("It's all ready exit");
return 0;
}
chiconysun
2011-06-02 · TA获得超过2.2万个赞
知道大有可为答主
回答量:5410
采纳率:92%
帮助的人:2534万
展开全部
最后一个do while循环的do自己找地方放好,只是将语法错误改了
#include "stdio.h"
#include "time.h"
#include "stdlib.h"

void main()
{
int computer,user;
char c;
srand ((unsigned)time(NULL));
printf("Starting!");
printf("Please input 1.Stone,2.Scissor,3.Paper");
scanf("%d",&user);
computer=rand()%3+1;
printf("Computer output is %s\n\n",computer==1?"Stone":computer==2?"Scissor":computer==3?"Paper": "");
switch (computer-user)
{
case 0:
printf("Draw!\n\n");
break;
case 1:
case -2:
printf("computer win!\n\n");
case -1:
case 2:
printf("You win!\n\n");
}
do{
printf("Continue the game please press Y,press other key will exit");
getchar();
c=getchar();
}
while (c=='y'||c=='Y');
printf("It's all ready exit");
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
dexahh
2011-06-02 · TA获得超过354个赞
知道答主
回答量:216
采纳率:100%
帮助的人:288万
展开全部
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
void main()
{
int computer,user;
char c;
srand ((unsigned)time(NULL));
printf("Starting!");
printf("Please input 1.Stone,2.Scissor,3.Paper");
scanf("%d",&user);
computer=rand()%3+1;
//printf("Computer output is %s\n\n",computer==1?"Stone":computer==2?"Scissor":computer==3?"Paper");
//三目运算符不匹配
printf("Computer output is %s\n\n",computer==1?"Stone":computer==2?"Scissor":computer==3?"Paper":"");
switch (computer-user)
{
case 0:
printf("Draw!\n\n");
break;
case 1:
case -2:
printf("computer win!\n\n");
case -1:
case 2:
printf("You win!\n\n");
}
printf("Continue the game please press Y,press other key will exit");
getchar();
c=getchar();
//}多了个}
//while (c=="y"||c=="Y")char 用''
while (c=='y'||c=='Y')
printf("It's all ready exit");
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
咖喱花盆Db
2011-06-02 · 超过10用户采纳过TA的回答
知道答主
回答量:75
采纳率:0%
帮助的人:27.2万
展开全部
改成下面这样就正确了:
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
void main()
{
int computer,user;
char c;
srand ((unsigned)time(NULL));
printf("Starting!");
printf("Please input 1.Stone,2.Scissor,3.Paper");
scanf("%d",&user);
computer=rand()%3+1;
printf("Computer output is %s\n\n",computer==1?"Stone":computer==2?"Scissor":"Paper");
switch (computer-user)
{
case 0:
printf("Draw!\n\n");
break;
case 1:
case -2:
printf("computer win!\n\n");
case -1:
case 2:
printf("You win!\n\n");
}
printf("Continue the game please press Y,press other key will exit");
getchar();
c=getchar();

while (c=='y'||c=='Y')
printf("It's all ready exit");
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
maohuiabc
2011-06-02 · TA获得超过197个赞
知道小有建树答主
回答量:113
采纳率:0%
帮助的人:143万
展开全部
自己看吧
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
void main()
{
int computer,user;
char c;
char *p1="Stone",*p2="Scissor",*p3="Paper";
srand ((unsigned)time(NULL));
printf("Starting!");

do{
printf("Please input 1.Stone,2.Scissor,3.Paper\n");
scanf("%d",&user);
computer=rand()%3+1;
// printf("Computer output is %s\n\n",computer==1?"Stone":computer==2?"Scissor":computer==3?"Paper");
printf("Computer output is %s\n\n",computer==1?"Stone":computer==2?"Scissor":computer==3?"Paper":" ");
switch (computer-user)
{
case 0:
printf("Draw!\n\n");
break;
case 1:
case -2:
printf("computer win!\n\n");
case -1:
case 2:
printf("You win!\n\n");
}
printf("Continue the game please press Y,press other key will exit\n\n");
getchar();
c=getchar();

}
while (c=='y'||c=='Y');

printf("It's all ready exit");
}
// while (c=='y'||c=='Y')
// printf("It's all ready exit");
//}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式