I have 3 Player
objects that I have passed as reference arguments in a function.
The function does the following:
- Creates a
vector
of the 3 objects and bubble sorts the them based on their score (data members). - Then it checks for first, second or third ranks and returns a resized
vector
.
In main
function, I am able to print the winner and her reward when I iterate through the vector
but it doesn't seem to update the actual objects. How can I update the objects?
This is what I have so far:
int enterBet(int balance, int maxBet);
vector <Player> chkWinner(Player &a, Player &b, Player &c, int pot);
bool sorting_method(Player &_1, Player &_2) {
//Bigger numbers go first
return _1.m_total > _2.m_total;
}
int main()
{
Player *player1 = new Player;
Player *player2 = new Player;
Player *player3 = new Player;
vector <Player> winnerArr;
winnerArr.resize(3);
int pot = 0;
int betAmount = 0;
int maxBet = 10;
player2->m_name = "Kelly";
player3->m_name = "Martha";
int x, y, z;
winnerArr[0] = *player1;
winnerArr[1] = *player2;
winnerArr[2] = *player3;
sort(winnerArr.begin(), winnerArr.end(), sorting_method);
cout << winnerArr[0].m_total << ", "
<< winnerArr[1].m_total << ", "
<< winnerArr[2].m_total << endl;
x = winnerArr[0].m_total;
y = winnerArr[1].m_total;
z = winnerArr[2].m_total;
if (x == y && x == z){
cout << "Divide pot by 3" << endl;
//totalArr.resize(3);
}
else if (x == y && x != z){
cout << "Divide pot by 2" << endl;
winnerArr.resize(2);
}
else{
cout << "Pay full Pot" << endl;
winnerArr.resize(1);
}
int payout;
if (winnerArr.size() == 3){
payout = ((pot * 5) / 3);
}
else if (winnerArr.size() == 2){
payout = ((pot * 5) / 2);
}
else if (winnerArr.size() == 1){
payout = (pot * 5);
for (int i = 0; i < winnerArr.size(); i++){
cout << winnerArr[i].m_name << " wins " << payout << endl;
winnerArr[i].m_balance += payout;
cout << winnerArr[i].m_balance << endl;
}
}
cout << player1->m_name << "'s total: " << player1->m_balance << endl;
cout << player2->m_name << "'s total: " << player2->m_balance << endl;
cout << player3->m_name << "'s total: " << player3->m_balance << endl;
break;
}