Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
Ok so my program is giving me an error in the WelcomePlayer() portion of the code. I also think after that is fixed there is something wrong with the...
Ok so my program is giving me an error in the WelcomePlayer() portion of the code. I also think after that is fixed there is something wrong with the DiceRoll() portion of the code. Any advice on how i can resolve these issue would be greatly appreciated. Thank you in advance!
The issues with the WelcomePlayer() begin with the m_players.SetNumber part. I'm getting an error. I'm not quite sure what is wrong as i've looked back at my previous assignments and have done the same thing as was done on them.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <cstdlib>
#include "LiarsDice1.21.h"
using namespace std;
void Game::WelcomePlayer()
{
system("CLS");
// initialize the random generator with current time
srand(time(NULL));
// declarations
int currentPlayer, dice, numPlayers;
// array declarations
// can store upto 1000 players and each player has 5 dice
int players[1000][5];
// get the number of players from user
cout << " How many players are playing: ";
cin >> numPlayers;
m_players.SetNumber(numPlayers);
cout << endl << "You entered " << m_players.GetNumber() << endl;
}
void Game::DiceRoll()
{
int currentPlayer, dice,
// run the loop upto numPlayers
for (currentPlayer = 0; currentPlayer < numPlayers; currentPlayer++)
{
if (currentPlayer == 0) {
cout << "players" << 1 << "t";
}
// generate the values for 5 dice and store the values in array
for (dice = 0; dice < 5; dice++)
{
// generate a random value
int random = rand() % 6 + 1;
// store the value
players[currentPlayer][dice] = random;
if (currentPlayer == 0) {
//std:: cout << "players"<<1<< "t";
cout << players[0][dice] << "t";
}
}
cout << endl;
void Game::GameRules() const
{
string line_;
//opens file
ifstream myReadFile;
myReadFile.open("rules.txt");
if (myReadFile.is_open()) {
while (getline(myReadFile, line_))//while file is open, it reads file lines
{
cout << line_ << "n";
}
myReadFile.close();//close file
}
else //if file is not open
cout << "File not open." << "n";
cin.get();
}
void Game::RunGame()
{
GameRules();
WelcomePlayer();
}
LiarsDice.h
#pragma once
#include "Player.h"
#include "PlayerOptions.h"
class Game
{
private:
void WelcomePlayer();
void GameRules() const;
void DiceRoll();
public:
void RunGame();
};
player.h:
#pragma once
class Player
{
private:
int m_players;
public:
Player()
{
}
void SetNumber(const int& numPlayers)
{
m_players = numPlayers;
}
const int& GetNumber() const
{
return m_players;
}
};
Game.h:
#include "stdafx.h"
#include "Player.h"
#include "LiarsDice1.21.h"
int _tmain(int argc, _TCHAR* argv[])
{
Game game;
game.RunGame();
return 0;
}
Ok so my program is giving me an error in the WelcomePlayer() portion of the code. I also think after that is fixed there is something wrong with the DiceRoll() portion of the code. Any advice on how i can resolve these issue would be greatly appreciated. Thank you in advance!
The issues with the WelcomePlayer() begin with the m_players.SetNumber part. I'm getting an error.