如果要加入显示电脑出了什么和你自己出了什么该怎么修改呢?如果再加上你现在几胜几败又该如何修改呢?
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
int Player,Computer,ping,win,lose;
int single=0;
ping=0;
win=0;
lose=0;
goto start1;
start: printf("please choose once again or end,once again input 1,end input 2.\n");
printf("yes or no:%i",single);
scanf("%i",&single);
if(single==1)
goto start1;
else if(single==2)
goto end;
else
printf("\nError choose,please choose again!\n");
goto start;
start1: printf("Start the game already\n" );
begin: printf ( "Plese input a number\n 1Scissors\n 2Rock\n 3Paper\n 4Quit\n");
scanf ( "%d", &Player);
if (Player>=4||Player<=0)
{
printf ("Inputerror!\nPlease input again!\n " );
goto begin;
}
srand (time(NULL));
Computer=1+rand()%3;
printf("%d\n",Computer);
if(Computer==Player)
printf ("Ping Ju!\n",ping++);
else if((Player-Computer)==1)
printf ("YOU WIN!\n",win++);
else if
(Player==1&&Computer==3)
printf("YOU WIN!\n",win++);
else
printf("YOU LOSE!\n",lose++);
single=0;
goto start;
end: printf("the total number of the game is :%i\n",ping+win+lose);
printf("out of the game and good luck!\n");
printf("this is your grade:\n");
printf("ping: %i\nwin: %i\nlose: %i\n",ping,win,lose);
}
这是我改写的,能够统计游戏次数,也能够统计总次数,而且可以无限制的游戏。不过我改来改去始终不能用 y 来表示继续,用 n 来表示结束,我尝试着用字符变量来表示,可是不知道怎么回事,那个 printf("\nError choose,please choose again!\n");始终会被调用两次,代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
int Player,Computer,ping,win,lose;
char single='\0';
ping=0;
win=0;
lose=0;
goto start1;
start: printf("please choose once again or end,once again input y,end input n.\n");
printf("yes or no:%c",single);
scanf("%c",&single);
if(single=='y')
goto start1;
else if(single=='n')
goto end;
else if(single='\0')
goto start;
else
printf("\nError choose,please choose again!\n");
clear: single='\0';
goto start;
start1: printf("Start the game already\n" );
begin: printf ( "Plese input a number\n 1Scissors\n 2Rock\n 3Paper\n 4Quit\n");
scanf ( "%d", &Player);
if (Player>=4||Player<=0)
{
printf ("Inputerror!\nPlease input again!\n " );
goto begin;
}
srand (time(NULL));
Computer=1+rand()%3;
printf("%d\n",Computer);
if(Computer==Player)
printf ("Ping Ju!\n",ping++);
else if((Player-Computer)==1)
printf ("YOU WIN!\n",win++);
else if
(Player==1&&Computer==3)
printf("YOU WIN!\n",win++);
else
printf("YOU LOSE!\n",lose++);
goto clear;
end: printf("the total number of the game is :%i\n",ping+win+lose);
printf("out of the game and good luck!\n");
printf("this is your grade:\n");
printf("ping: %i\nwin: %i\nlose: %i\n",ping,win,lose);
}
我也是个新手,程序写得很臭(已被前辈骂过数次了),请各位大侠不吝赐教啦!o(∩_∩)o...
[[it] 本帖最后由 kscus 于 2008-9-14 13:18 编辑 [/it]]