Question
Need help with one last step of this program. The program allows 100 Players to play a game of rolling dice where each player will
Need help with one last step of this program. The program allows 100 Players to play a game of rolling dice where each player will roll 20 dice. I have the program working and get the correct results. The only help I need is to display the winning player's dice in 5 rows of 5. This should be done in the Source.cpp file. Here is the code for the Source.cpp and Player.h files:
Source.cpp
#include
using namespace std;
void setPlayerNumbers(Player players[]); Player* getHighestScorer(Player players[]); void printPlayer(Player* player); void testPlayerRolls(Player players[]);
int main() { srand(time(0)); // seed the random number generator
Player players[100];
setPlayerNumbers(players); testPlayerRolls(players);
Player* highestScorer = getHighestScorer(players); printPlayer(highestScorer);
return 0; }
void setPlayerNumbers(Player players[]) { for (int i = 0; i < 100; i++) { players[i].setPlayerNumber(i); } }
Player* getHighestScorer(Player players[]) { Player* highestScorer = &players[0]; for (int i = 1; i < 100; i++) { if (players[i].getSumOfDice() > highestScorer->getSumOfDice()) { highestScorer = &players[i]; } } return highestScorer; }
void printPlayer(Player* player) { cout << "Player " << player->getPlayerNumber() << " had the highest total of " << player->getSumOfDice();; }
void testPlayerRolls(Player players[]) { for (int i = 0; i < 100; i++) { players[i].play(); } }
Player.h
#pragma once #include "Die.h"
class Player { public: Player(); // constructor void play(); // roll all dice and calculate sum int getNumberOfDice(); // return the number of dice int getPlayerNumber(); // return the player number int getSingleDieValue(int index); // return the value of a single die int getSumOfDice(); // return the sum of all dice void setPlayerNumber(int num); // set the player number private: Die* dice = new Die[20]; // array of dice int playerNumber; // player number int sumOfDice; // sum of all dice };
If any more code is needed just let me know
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started