I have the problems with initialized number from another cpp file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Dice::Dice(int num1, int num2)
:numberone(num1), numbertwo(num2)
{
}
int Dice::roll()
{
Random n1(1, 6); // random from 1-6 from another cpp ( this is fine)
Random n2(1, 6);
//numberone = n1.get();
numberone = rand() % 6 + 1; // even if i tried to used this the main function still doesnt have any value for dice
numbertwo = n2.get(); // this one is the random.cpp
return numberone, numbertwo;
}
My main
1 2 3 4 5 6 7 8 9 10
Dice dice(dnum1, dnum2);
dice.roll(); // It doesnt work it need to give value for dnum1 and dnum2
// TESTING VALUE
std::cout << dnum1 << std::endl;
std::cout << dnum2 << std::endl;
Line 6 states that the roll() returns an integer. One integer. A function can return at most one object. The line 13 does return one integer, but you have to read the description of the comma operator to know what that value is.
Your main does not store the integer returned by the roll().
Your main has to pass two integer values to the constructor of Dice object. In other words, the dnum1 and dnum2 must have values before line 2.
However, the roll() changes the member variables of the dice, so the values given via constructor did not serve apparent purpose.
If you want to show the new rolled values, you have to retrieve them from the dice.
PS. Forget the "from another cpp"; there is only one whole program. The organization of the source code plays no role during runtime.
A function cannot return 2 or more values at the same time.
Also, dnum1 and dnum2 are passed to Dice::Dice to initialize the Dice::numberone and Dice::numbertwo.
Hence, after the statement Dice dice(dnum1, dnum2);, dnum1 and dnum2 still remain the same.
Consider using get functions to retrieve numberone and numbertwo from the dice.