比赛规则:
1。胜利条件:7局4胜。胜一局记一分。
2。胜一局条件:赢一个球记一点,其中一人拿到11点以上,并且和另外一人相差相差2点,则胜。
#include "stdio.h"
#include "math.h"
#define GAME_TOTAL 7
void input(); //输入每局比赛结果
void scoring(int A, int B); //记录A,B的分数
void check_round(int *point_A, int *point_B); //检查每局输入比赛结果是否正确
int check_end(); //检查比赛是否结束
int score_A=0,score_B=0;
void main()
{ int round;
printf("begin playing!!/n");
for(round=1;round<=GAME_TOTAL;round++)
{
printf("/nthe %d round/n",round);
input();
if(check_end())
break;
}
}
void input()
{
int point_A=0,point_B=0;
printf("/nplease enter the score of A:");
scanf("%d",&point_A);
getchar();
printf("/nplease enter the score of B:");
scanf("%d",&point_B);
getchar();
check_round(&point_A,&point_B);
}
void check_round(int *point_A, int *point_B)
{
if((*point_A)>=11||(*point_B)>=11)
{
if (fabs((double)((*point_A)-(*point_B)))>=2)
{
printf("/ndate enter ok!/n");
scoring(*point_A,*point_B);
}
else
{
printf("/ninput error!!!/n");
input();
}
}
else
{
printf("/ninput error!!!/n");
input();
}
}
void scoring(int A, int B)
{
if (A>B)
score_A++;
else if(B>A)
score_B++;
}
int check_end()
{
if(score_A>=4||score_B>=4)
{
if(score_A>score_B)
printf("/nA wins/n");
else if(score_A<score_B)
printf("/nB wins/n");
return(1);
}
else return(0);
}
记:check_round有些瑕疵。。