前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >乒乓球比赛的记分表-统计乒乓球分数,含结构体的赋值与读取

乒乓球比赛的记分表-统计乒乓球分数,含结构体的赋值与读取

原创
作者头像
eisc
修改2024-03-14 08:16:17
1240
修改2024-03-14 08:16:17
举报
代码语言:c
复制


#---- TableTennis.h ----#

typedef struct
{  
    int aCount;
    int aStatusFlag;
    int aWinFourgamesFlag;
    int aCompetentFlag;

}aScoreStruct;
extern aScoreStruct aScoreS;

typedef struct
{  
    int bCount;
    int bStatusFlag;
    int bWinFourgamesFlag;
    int bCompetentFlag;

}bScoreStruct;
extern bScoreStruct bScoreS;







#---- TableTennis.c ----#

#include <stdio.h>
#include "TableTennis.h"

aScoreStruct aScoreS;
bScoreStruct bScoreS;           // 结构体声明,引用,理解为: 结构体 被 bScoreS 继承

#define  ScoreZero      0       // 定义常量变量,理解为 普通变量 后面是赋值 0 
#define  ScoreFour      4
#define  ScoreTen       10
#define  ScoreEleven    11
#define  ScoreTwelve    12

static int VictoryExitFlag = 0; // static 静态变量  其数值 为0 不被更改,一般在函数内:被其他方法赋值后,在其他if 或者 for 等方法中 不希望保留数值,而是每次都是 0 进行使用 
static int abTieFlag = 0;

void Counting_Score(aScoreStruct *_aScoreS,bScoreStruct *_bScoreS,int inputData[2])     
{                              // 结构体 赋值给 指针,main 函数调用本函数需要传递内存地址
    if( inputData[0] == 1 )
    {
        _aScoreS->aStatusFlag = 1;
        _aScoreS->aCount++;
    }
    else
    {
        _bScoreS->bStatusFlag = 1;
        _bScoreS->bCount++;
    }

    if(_aScoreS->aCount == ScoreFour && _bScoreS->bCount == ScoreZero)
    {
        VictoryExitFlag = 1;
        aScoreS.aWinFourgamesFlag = 1;
        printf("\n a 胜利,连胜 %d 局 \n",ScoreFour);
    }
    
    if(_aScoreS->aCount == ScoreZero && _bScoreS->bCount == ScoreFour)
    {

        VictoryExitFlag = 1;
        bScoreS.bWinFourgamesFlag = 1;
        printf("\n b 胜利,连胜 %d 局 \n",ScoreFour);
    }

    if( _bScoreS->bCount == ScoreTen && _aScoreS->aCount == _bScoreS->bCount ) 
    {
        printf("\n a b 在 %d : %d 中平局,需要加局赛 \n",ScoreTen,ScoreTen );
        abTieFlag = 1;
    }

    if( _aScoreS->aCount == ScoreTwelve && abTieFlag == 1)
    {
        VictoryExitFlag = 1;
        printf("\n a 胜利,得分: %d ; 来自: %d : %d 平局加局赛 \n",_aScoreS->aCount, ScoreTen,ScoreTen);
    }

    if( _bScoreS->bCount == ScoreTwelve && abTieFlag == 1)
    {
        VictoryExitFlag = 1;
        printf("\n b 胜利,得分: %d ; 来自: %d : %d 平局加局赛 \n",_bScoreS->bCount, ScoreTen,ScoreTen);
    }

    if( _aScoreS->aCount == ScoreEleven && abTieFlag == 0)
    {
        VictoryExitFlag = 1;
        printf("\n a 胜利,得分: %d ; 来自:先得 11 分\n",_aScoreS->aCount);
    }

    if( _bScoreS->bCount == ScoreEleven && abTieFlag == 0)
    {
        VictoryExitFlag = 1;
        printf("\n b 胜利,得分: %d ; 来自:先得 11 分\n",_bScoreS->bCount);
    }
}

int TableTennis(void)
{
    for(;;)
    {
        int inputData[2];

        if( VictoryExitFlag == 1 )
        {
            printf("\n 统计结束 \n");
            break;
        }

        printf("\n 输入 A 的分数,然后回车输入B的分数 \n");
        for(int i=0;i<2;i++)
        {
            scanf("%d",&inputData[i]);
        }

        Counting_Score(&aScoreS,&bScoreS,inputData);

        printf("\n aScoreS.aCount = %d,aScoreS.aWinFourgamesFlag = %d,\n bScoreS.aCount = %d,bScoreS.bWinFourgamesFlag = %d",aScoreS.aCount,aScoreS.aWinFourgamesFlag,bScoreS.bCount,bScoreS.bWinFourgamesFlag);
    }
}

int main()
{
    TableTennis();
}







原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档