当前位置:网站首页>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;
}边栏推荐
猜你喜欢
随机推荐
抖音实战~首页视频~下拉刷新
IK分词器
Six necessary threat tracking tools for threat hunters
黑客用机器学习发动攻击的九种方法
Arduino UNO + DS1302利用31字节静态RAM存储数据并串口打印
tsconfig. json
项目实战五:搭建ELk日志收集系统
Analysis on development technology of NFT meta universe chain game system
数据库SQL语句撰写
(几何) 凸包问题
转:实事求是
Redis single sign on system + voting system
String string is converted to jsonarray and parsed
手机影像内卷几时休?
成功解决之Jenkins报错:The goal you specified requires a project to execute but there is no POM
The goal you specified requires a project to execute but there is no POM
WebView load pdf
Some basic mistakes
uni-app使用canvas绘制二维码
好物推荐:移动端开发安全工具









