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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
//Score Tracker
#include <iostream>
#include <string>
using namespace std;
struct hiScores{
string user;
int score;
};
void enterNewScore(hiScores records[50], int index);
void allScoresUser(hiScores records[50], int index);
void topTen(hiScores records[50], int index);
void allScoresEvery(hiScores records[50], int index);
void menu(hiScores records[50], int index);
int main()
{
hiScores records[50];
int index = 0; //lowest unused position in the array.
menu(records, index);
}
void menu(hiScores records[50], int index)
{
int choice = 42;
while (choice >= 6 || choice <= 0)
{
cout << "\nPlease enter the number that corresponds to your choice:";
cout << "\n 1). Enter new score";
cout << "\n 2). Display all scores by specific user";
cout << "\n 3). Top ten scores";
cout << "\n 4). All scores saved";
cout << "\n 5). Exit\n";
cin >> choice;
switch (choice)
{
case 1: enterNewScore(records, index);
break;
case 2: allScoresUser(records, index);
break;
case 3: topTen(records, index);
break;
case 4: allScoresEvery(records, index);
break;
case 5: cin.ignore();
cin.get();
}
}
}
void enterNewScore(hiScores records[50], int index)
{
cout << "\n\nPlease enter the name of the person with the score : "; // still need to add code to replace low scores when array is full
cin >> records[index].user;
cout << "\nEnter your score : ";
cin >> records[index].score;
index++;
menu(records, index);
}
void allScoresUser(hiScores records[50], int index)
{
string nameSearch[50]; // list of each name associated with a record
int NSindex = 0; // index of lowest empty spot in nameSearch
for (int i = 0; i < index; i++)
{
for (int j = 0; j < NSindex; j++)
{
bool notOnList = false;
if (records[i].user != nameSearch[j])
{
notOnList = true;
}
if (notOnList == true)
{
nameSearch[NSindex] = records[i].user;
NSindex++;
}
}
}
cout << "\nNames of record holders\n";
for (int i = 0; i < NSindex; i++)
{
cout << nameSearch[i] << endl;
}
string inquiry;
cout << "Who's name do you want to look up?";
cin >> inquiry;
cout << "Displaying all scores for "<< inquiry << ":" << endl;
for (int i = 0; i < index; i++)
{
if (records[i].user == inquiry)
{
cout << records[i].user << " " << records[i].score << endl;
}
}
menu(records, index);
}
void topTen(hiScores records[50], int index)
{
cout << "\n\nThis is where you see top ten scores";
menu(records, index);
}
void allScoresEvery(hiScores records[50], int index)
{
cout << "User Name Score\n";
cout << "--------- -----\n";
int i = index - 1;
for (i; i >= 0; i--)
{
cout << records[i].user << " " << records[i].score << endl;
}
cout << "\n\nThis is where you see all records";
menu(records, index);
}
|