当前位置:网站首页>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;
}
边栏推荐
- 数据库范式和主码的选择
- Successfully solved the problem of garbled microservice @value obtaining configuration file
- Pinda general permission system (day 1~day 2)
- Six necessary threat tracking tools for threat hunters
- 黑客用机器学习发动攻击的九种方法
- 关于不等式取值转义的思路
- 问题解决:虚拟机无法复制粘贴文件
- SSO微服务工程中用户行为日志的记录
- When does the mobile phone video roll off?
- 物联网协议的王者:MQTT
猜你喜欢
随机推荐
Tiktok practice ~ sharing module ~ generate short video QR code
Invocation failed Unexpected end of file from server
Résumé des points de connaissance
项目实战五:搭建ELk日志收集系统
IK word breaker
【Kubernetes】Kubernetes 原理剖析与实战应用(更新中)
Unit test of boot
NFTGameFi链游系统开发详解方案丨链游系统开发原理解析
刷新三观的HP-UX系统中的强指针赋值出core问题
Tiktok practice ~ search page ~ video details
Kubernetes 资源拓扑感知调度优化
Installation and use of filebeat
Some cold knowledge about QT database development
8VC Venture Cup 2017 - Final Round C. Nikita and stack
50 lines of code to crawl TOP500 books and import TXT documents
Micro service single sign on system (SSO)
Summary of knowledge points
Résolution du problème: la machine virtuelle n'a pas pu copier et coller le fichier
Tiktok practice ~ sharing module ~ short video download (save to photo album)
Union, intersection and difference operations in SQL