-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreBoard.cpp
62 lines (59 loc) · 1.32 KB
/
ScoreBoard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//score board for Game WordFever!
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <string.h>
#ifdef _WIN64
#define CLEAR system("cls")
#elif _WIN32
#define CLEAR system("cls")
#else
#define CLEAR system("clear")
#endif
using namespace std;
static int ScoreBoard()
{
extern int back;
string namelist[100] = {};
int scorelist[100] = {};
string name, tempname;
int i = 0;
int score, tempscore;
CLEAR;
ifstream fin("PlayerRecord.txt");
if (fin.fail()){
cout << "\n\n No record! Back to menu..";
back = 1;
}
while (fin >> name >> score){
namelist[i]=name;
scorelist[i]=score;
i+=1;
}
int recordnum =i;
for (int i=0; i<recordnum;i++){
for (int j=0; j<recordnum;j++){
if (scorelist[i]>scorelist[j]){
tempname = namelist[i];
namelist[i] = namelist[j];
namelist[j] = tempname;
tempscore = scorelist[i];
scorelist[i] = scorelist[j];
scorelist[j] = tempscore;
}
}
}
cout << "\n\n"<<setw(10)<<"Name"<<setw(22)<<"Score\n";
cout << " =======================================\n";
for (int i=0;i<recordnum;i++)
{
cout << setw(10)<< namelist[i]<<" "<<setw(20)<<scorelist[i] <<"\n\n";
}
cout << " =======================================\n";
cout <<" Press <Enter> to back to menu......\n\n";
back = 1;
cin.get();
cin.get();
return 0;
}