void HighScore::ShowRank(HighScore & account) {
if(account.highScore.size() == 0){ cout << "The score board is empty." << endl; }
for (int i = 0; i < account.highScore.size() - 2; i++) {
if (account.highScore[i] > account.highScore[i + 1]) {
swap(account.highScore[i], account.highScore[i + 1]);
}
for (int j = 0; j < account.highScore.size(); j++) {
cout << "Rank " << j+1 << ". " << account.highScore[j] << endl;
}
}
system("pause");
system("cls");
}
Currently the way I have set it up is: aManager.ManageAccounts(aManager;
inside ManageAccounts aManager allocates a new Object: AccountManager NEWUSER = account.newUser();
It currently does not swap and when it COUTS it couts 3x for all 3 objects (I only want it to cout NEWUSER. I will link my full code bellow (Too long):
1. What are lines 3-6 supposed to be accomplishing? Is it a sort?
2. Why does a function with "Show" in its name modify the data it shows?
3. Why is an output loop inside another loop that modifies what is displayed?
4. Don't pass an object of the class to class member functions. This construction: object.function(object) is particularly unnecessary. Just object.function() is enough. You can refer to object inside the function by means of the this pointer.
1. What are lines 3-6 supposed to be accomplishing? Is it a sort?
It is a sort
2. Why does a function with "Show" in its name modify the data it shows?
Am I better off having a print and a sort function?
3. Why is an output loop inside another loop that modifies what is displayed?
Typo, which fixed both the cout and swap.
4. Don't pass an object of the class to class member functions. This construction: object.function(object) is particularly unnecessary. Just object.function() is enough. You can refer to object inside the function by means of the this pointer.
I was just working on this, for this situation must I use THIS-> every time? or can I simply do:
swap(highScore[i], highScore[i + 1]);
Thank you for your help, that pretty much fixed my issue. The small problems always get me.