用C语言编的石头剪刀布的小游戏谁有空帮我看看

来源:百度知道 编辑:UC知道 时间:2024/05/26 20:01:48
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
main()
{
int a,b;
char put,c;
puts("Are you ready!The Game begine!\n");
k: puts("please enter your answer:");
scanf("%c",&put);
srand((unsigned)(time)(NULL));
b=rand()%3;
switch(put)
{
case 'S': a=0; break;
case 'J': a=1; break;
case 'B': a=2; break;
default : {puts("sorry you must enter 'J'.'S'or'B!'");输入d为什么输出两次sorry you must enter 'J'.'S'or'B!
goto k;
}
}
if(a==b)
{
if(a==0) puts("打平啦!电石对你石");
if(a==1) puts("打平啦!电剪对你剪");
if(a==2) puts("打平啦!电布对你布");

}
else
{
if(b==0)
{
if(a==1) puts("你输啦!电石对你剪");
if(a==2) puts("你赢啦!电石对你布");

}
if(b=

这个问题已经问了几天了是不是都是你问的,挺执着的,回答一下吧。
你的程序编的挺好,只是缺乏一点:想用scanf反复输入数据的话,要记得及时清除输入缓冲区,否则下次再调用时里边存的数据还在,因而出现问题。使用
fflush(stdin);
进行清理,我把源程序改了一下:
/////////////////////////////////////////////
//石头剪刀布.cpp reload
/////////////////////////////////////////////
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
main()
{
int a,b;
char put,c;
puts("Are you ready!The Game begine!\n");

k:fflush(stdin) ;
puts("please enter your answer:");
scanf("%c",&put);
srand((unsigned)(time)(NULL));
b=rand()%3;
switch(put)
{
case 'S': a=0; break;
case 'J': a=1; break;
case 'B': a=2; break;
default : {puts("sorry you must enter 'J'.'S'or'B!'");
fflush(stdin);//输入d为什么输出两次sorry you must enter 'J'.'S'or'B!
goto k;
}