I'm working on a Dice game for a school project and am having trouble utilizing the srand and rand functions. I know which function it is supposed to be implemented in but I'm having trouble setting it up. (NOTE: The project runs and is near completion, the only problem is getting the dice to randomize instead of staying the same. I'm not asking you to do my program for me) Here is my code, kinda long but I believe you would need to see the classes. The function I'm working on is Toss(void) in the cdie.cpp file.
(another note: pay no attention to the use of auto, I know its deprecated, I've heard it a million times but that's how our teacher taught us.)
#include <iostream>
#include <cstdlib>
#include "cdiceplayer.h"
usingnamespace std;
// ==== main ==================================================================
//
// ============================================================================
int main(void)
{
autoint numDice;
// ask the user how many dice to play with
cout << "How many dice would you like to roll? ";
if (!(cin >> numDice))
{
cout << "Invalid input..." << endl;
exit(EXIT_FAILURE);
}
// using the user input, create the dice player object
auto CDicePlayer player = numDice;
autochar response;
// loop and let the good times roll!
do {
// roll the dice and show 'em!
player.RollDice();
player.ShowDice();
// display the total value
cout << "The total is: " << player.GetTotal() << endl;
// see if the user wishes to roll again
cout << "Roll again? ";
cin >> response;
} while ('y' == tolower(response));
cout << "Thanks for playing!" << endl;
return 0;
} // end of "main"
I have tried that and it wont change the output. If I use 3 die, all the die will display the same number. I know I'm placing the rand() in the right function, the problem is that it randomizes one number and then uses that number for each diee. Also I can't modify my main.cpp file, should have clarified that earlier.