Commit cfc1469c authored by Kyle Malaguit's avatar Kyle Malaguit

autosave

parent 6949db4d
......@@ -47,4 +47,19 @@ void SaveLoad::userInputNameMakeScore(int intScore){
pushBackNewScoreAndSort(Scores(userNameInput, intScore));
}
void SaveLoad::printScoreIfLessThan10(Scores findScore){
vector<Scores>::iterator iter;
cout << "Finding Score..\n";
iter = find(scores.begin(), scores.end(), findScore);
if(iter != scores.end()){
//use iterator to return position in vector
cout << "Score found "<< (iter - scores.begin())+1 << endl;
}else{
cout << "Score not found" << endl;
}
// cout << iter << " " << scores.at(iter).getName << " " << scores.at(iter).getScore << endl;
}
\ No newline at end of file
......@@ -28,6 +28,11 @@ class SaveLoad {
//display scores in the bash
void displayScores();
//if score is less than top ten print score
void printScoreIfLessThan10(Scores);
//one that passes a position and returns the line in the vector
//function for comparing
static bool sortAscending(Scores, Scores);
......
......@@ -13,10 +13,13 @@ class Scores{
}
//accessors
string getName(){return name;}
int getScore(){return score;}
string getName() const {return name;}
int getScore() const {return score;}
//overload = so that it can be compared
bool operator ==(const Scores &s) const {return this->getName() == s.getName() && this->getScore() == s.getScore();}
private:
string name;
int score;
......
......@@ -12,13 +12,13 @@ int main(){
//check for valid username
// char userName[3];
SL2048 second;
second.LoadContainers();
second.userInputNameMakeScore(10000);
second.LoadContainers("snakedata.txt");
second.updateFile();
second.updateFile("snakedata.txt");
second.displayScores();
Scores fScore("cdo", 21474);
second.printScoreIfLessThan10(fScore);
return 0;
......
Rank Name Score
1 nge 654346
2 vfd 45365
3 cdn 21474
4 ooo 10000
5 LOP 10000
6 vfr 9999
7 ddd 9999
8 Kyl 9999
9 PPP 9999
10 bbb 9999
Finding score rank ...
cdn
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment