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;
count <><><>
count <><><>
die1.roll();
count <><><>
die 2.roll();
count <><><>
count <><>
<><>
die1.roll();
die2.roll();
count <><>
<><>
return 0;
} //end main
-------------------------------------------------------------------------
die.cpp
#include
#include
#include
#include "die. h"
using namespace std;
die::die()
{
//num = 1; -----------This is the old code
// sr and (time(0)); -----------This is the old code
random _device r device{};
default _random_ engine num s{ r device() };
uniform _int_ distribution random Num{ 1,6 };
}
void die::roll()
{
//num = rand() % 6 + 1; -----------This is the old code
num = random Num(num s);
}
int die::get Num() 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 get Num() const;
//Function to return the number on the top face of the die.
//Returns the value of the instance variable num.
private:
int num;
};