当前位置:网站首页>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;
}边栏推荐
- Invocation failed Unexpected end of file from server
- Tiktok practice ~ sharing module ~ short video download (save to photo album)
- Usage and difference between ros:: spinonce() and ros:: spin()
- Summary of alter operation in SQL
- wm_ Concat() and group_ Concat() function
- Project practice 5: build elk log collection system
- The eigen library calculates the angle between two vectors
- 成功解决之Jenkins报错:The goal you specified requires a project to execute but there is no POM
- WebView load pdf
- Solidity - 合约继承子合约包含构造函数时报错 及 一个合约调用另一合约view函数收取gas费用
猜你喜欢
随机推荐
两个文件 合并为第三个文件 。
Kubernetes resource topology aware scheduling optimization
Conditional compilation in precompiling instructions
Summary of several common UML diagrams
Summary of knowledge points
Kubernetes 资源拓扑感知调度优化
JS mobile terminal touch screen event
uni-app使用canvas绘制二维码
Some basic mistakes
C语言 文件光标 fseek
Chain game development finished product source code chain game system development details
Union, intersection and difference operations in SQL
Minimum spanning tree, shortest path, topology sorting, critical path
Database SQL statement writing
【推荐收藏】这8个常用缺失值填充技巧一定要掌握
Tiktok practice ~ sharing module ~ copy short video link
读书笔记:《过程咨询 III》
关于不等式取值转义的思路
Numpy之matplotlib
How to create and enforce indexes









