Question
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
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;i
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;i void declareWinner(Player *pls, int numPls) { bool isWin=false; for(int i=0;i 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 //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 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
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