I messed up my dice program. I wanted to use the #include, but messed up. The code is suppose to roll a dice, display it and re-roll the die again. I highlighted the code that I think is the problem....


I messed up my dice program. I wanted to use the #include, but messed up. The code is suppose to roll a dice, display it and re-roll the die again. I highlighted the code that I think is the problem.


main.cpp


#include


#include "die.h"


using namespace std;


int main() {

die die1;

die die2;



cout <><>

cout <><>



die1.roll();

cout <><>



die2.roll();

cout <><>



cout <><>

<>



die1.roll();

die2.roll();



cout <><>

<>



return 0;

} //end main

-------------------------------------------------------------------------


die.cpp


#include


#include


#include


#include "die.h"


using namespace std;


die::die()

{

//num = 1; -----------This is the old code

//srand(time(0)); -----------This is the old code



random_device rdevice{};

default_random_engine nums{ rdevice() };

uniform_int_distribution randomNum{ 1,6 };

}


void die::roll()

{

//num = rand() % 6 + 1; -----------This is the old code



num = randomNum(nums);

}


int die::getNum() const

{

return num;

}


------------------------------------------------------------------------------------


die.h


class die

{

public:

die();

//Default constructor

//Sets the default number rolled by a die to 1



void roll();

//Function to roll a die.

//This function uses a random number generator to randomly

//generate a number between 1 and 6, and stores the number

//in the instance variable num.



int getNum() const;

//Function to return the number on the top face of the die.

//Returns the value of the instance variable num.


private:

int num;

};





















May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here