当前位置:网站首页>Case description: the competition score management system needs to count the competition scores obtained by previous champions and record them in the file. The system has the following requirements: -
Case description: the competition score management system needs to count the competition scores obtained by previous champions and record them in the file. The system has the following requirements: -
2022-06-26 19:27:00 【laocooon】
Case description : Competition score management system , It is necessary to count the scores of previous champions , And record it in the file , The system has the following requirements :
- Open the system to have a welcome interface , And display the selectable options
- Options 1: Record game scores
- Options 2: Look at past records
- Options 3: Clear the game record
- Options 4: Exit the current system
According to the user's different input , Implement different requirements , If other values are entered , It is deemed to clear the screen and reselect
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*
Case description : Competition score management system , It is necessary to count the scores of previous champions , And record it in the file , The system has the following requirements :
- Open the system to have a welcome interface , And display the selectable options
- Options 1: Record game scores
- Options 2: Look at past records
- Options 3: Clear the game record
- Options 4: Exit the current system
According to the user's different input , Implement different requirements , If other values are entered , It is deemed to clear the screen and reselect
*/
int FileIsEmpty = 0; // 1 Represents that the file is empty 0 The file is not empty
void clearFile()
{
if (FileIsEmpty)
{
printf(" The file record is empty !\n");
system("pause");
system("cls");
return;
}
printf(" Make sure to clear ?\n");
printf("1、 determine !\n");
printf("2、 return !\n");
int select = 0;
int num = scanf("%d", &select);
if (select == 1)
{
FILE* fp = fopen("score.txt", "w");
fclose(fp);
printf(" Emptying complete !\n");
FileIsEmpty = 1;
}
system("pause");
system("cls");
}
void initFlag()
{
FILE* fp = fopen("score.txt", "r");
if (fp == NULL)
{
printf(" File opening failure \n");
return;
}
char ch = fgetc(fp);
if (ch == EOF)
{
//printf(" The file is empty \n");
FileIsEmpty = 1;
}
else
{
//printf(" The file is not empty \n");
FileIsEmpty = 0;
}
}
// Record score
void setScore()
{
printf(" Please enter a new record score :\n");
double score = 0;
int num = scanf("%lf", &score);
FILE* fp = fopen("score.txt", "a"); //a Represents the way to write a file by appending
if (fp == NULL)
{
printf(" File opening failure !\n");
return;
}
fprintf(fp, "%lf\n", score);
printf(" Score recorded successfully !\n");
FileIsEmpty = 0;
// Close file
fclose(fp);
system("pause");
system("cls");
}
void showScore()
{
if (FileIsEmpty)
{
printf(" The file record is empty !\n");
system("pause");
system("cls");
return;
}
FILE* fp = fopen("score.txt", "r");
int index = 1;
while (!feof(fp))
{
double score;
int ret = fscanf(fp, "%lf", &score);
//if (feof(fp))
if(ret == -1)
{
break;
}
printf("%d The session score is : %.2lf\n", index, score);
index++;
}
fclose(fp);
system("pause");
system("cls");
}
void show_Menu()
{
printf("*********************************************\n");
printf("************* Welcome to this program *************\n");
printf("************* 1、 Record game scores *************\n");
printf("************* 2、 Look at past records *************\n");
printf("************* 3、 Clear the game record *************\n");
printf("************* 4、 Exit the current system *************\n");
printf("*********************************************\n");
}
int main()
{
initFlag();
int choice = 0; // Used to store the user's selection
int num = 0;
while (1)
{
show_Menu();
printf(" Please enter your choice :\n");
num = scanf("%d", &choice);
switch (choice)
{
case 1: // Record game scores
setScore();
break;
case 2: // Look at past records
showScore();
break;
case 3: // Clear the game record
clearFile();
break;
case 4: // Exit the current system
printf(" Welcome to use... Next time \n");
system("pause");
exit(0); // Exit the current system
break;
default:
system("cls");
break;
}
}
system("pause");
return EXIT_SUCCESS;
}边栏推荐
- 抖音实战~分享模块~短视频下载(保存到相册)
- DAPP丨LP单双币流动性质押挖矿系统开发原理分析及源码
- 两个文件 合并为第三个文件 。
- Tiktok practice ~ search page ~ video details
- 威胁猎人必备的六个威胁追踪工具
- 抖音实战~搜索页面~扫描二维码
- Summary of knowledge points
- Jsonutils tool class (based on Alibaba fastjson)
- The king of Internet of things protocol: mqtt
- Tiktok practice ~ homepage video ~ pull-down refresh
猜你喜欢

Boot indicator monitoring

Unity——Mathf. Similarities and differences between atan and atan2

数据库SQL语句撰写

Some basic mistakes

Microservice architecture

Micro service single sign on system (SSO)

关于Qt数据库开发的一些冷知识

xlua获取ugui的button注册click事件

The successfully resolved idea cannot use the log normally after referencing Lombok's @slf4j

Database SQL statement writing
随机推荐
Usage and difference between ros:: spinonce() and ros:: spin()
mongoDB的三种基础备份方法
Summary of alter operation in SQL
Project practice 5: build elk log collection system
Deep learning: numpy
Summary of knowledge points
Solidity - 合约继承子合约包含构造函数时报错 及 一个合约调用另一合约view函数收取gas费用
The goal you specified requires a project to execute but there is no POM
Web resource preloading - production environment practice
Using recursion to find all gray codes with n bits
Uni app uses canvas to draw QR code
Boot指标监测
数据库范式和主码的选择
Redis Basics
xlua获取ugui的button注册click事件
Basic and necessary common plug-ins of vscade
String string is converted to jsonarray and parsed
mysql的充值问题
Clion breakpoint single step debugging
On the escape of inequality value