Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ I am working on an LCR game. I have it working great but when I try to add the piece of code so that

C++

I am working on an LCR game. I have it working great but when I try to add the piece of code so that it can read the rules from a txt file I get the following errors.

'argument' conversion from 'time_t' to 'unsigned int', possible loss of data line 16 dice.h

function 'int main(void)' already has a body lcr game.cpp line 145

this is the code

LCR game.cpp

#include "pch.h" #include #include #include #include #include "Dice.h" #include "Player.h" #include using namespace std;

int main() { string line; //will hold the information that is read from the text file ifstream in("rules.txt"); // to read the text of rules.txt if (in.is_open()) // the is _open will be true if the stream is able to associate with the file {

while (getline(in, line)) //it takes input stream and line in order to get and store the information { cout << line << ' '; // display the rules found in the rules text that were stored thanks to the above lines } in.close(); } else { cout << "Unable to open file"; // display this in case it is not able to read the txt } return 0; }

bool checkIsFinishsed(Player *pls, int numPls) { int count=0; // to check if the game is finished already for(int i=0;i0) count++; } if(count>1) return false; else return true; //apply on all the chips }

Player* takeInput(int &numPls) { Player *pls; cout<<"Enter number of players: "; cin>>numPls; string nam; //take input from the user //take input all players, and update the chips while(numPls<3) { cout<<"Please Enter at least 3 players: "; cin>>numPls; } pls=new Player[numPls]; cin.ignore(); for(int i=0;i

void displayPlayers(Player *pls, int numPls) { cout<<"Player Number\tPlayer Name\tChips"<

Player* playGame(int &numPls) { Player *pls; pls=takeInput(numPls); Dice mydice; while(!checkIsFinishsed(pls, numPls)) { for(int i=0;i3) chips=3; for(int j=0;j

void declareWinner(Player *pls, int numPls) { bool isWin=false; for(int i=0;i0) { cout<<"Player number "<<(i+1)<<", named "<

int main() { Player *pls=NULL; int numPls=0;

pls=playGame(numPls); declareWinner(pls, numPls);

return 0; //main fucntion to iterate over all functions }

Dice.h

#ifndef DICE_H #define DICE_H #include #include using namespace std;

//Dice class class Dice { private: int value; public: void roll() { srand(time(NULL)); int val=rand() % 6 + 1; this->value=val;//this methods rolls the dice //it generates random number between 1 to 6 } int getValue() { //it returns the dice value return this->value; } };

#endif

Player.h

#ifndef PLAYER_H #define PLAYER_H #include #include using namespace std;

class Player { private: string name; int chips; public: void setName(string nam) { this->name=nam; } string getName() { return this->name; } void setChips(int chip) { this->chips=chip; } int getChips() { return this->chips; } };

#endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions