乒乓球比赛

比赛规则:

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有些瑕疵。。
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值