Hey, I'm trying to create a simple Yatzy game in C++ (I'm new to programming) anyway here is my code:
void gameMechanics(int& numberOfPlayers) //NumberOfPlayers are not used in this function at this point.
{
int diceResult = 0;
int fiveDices[4];
string throwDices;
cout << "Throw dices?(y/n): ";
getline(cin, throwDices);
if(throwDices == "n" || throwDices == "N")
{
cout << "Game Over then...";
Sleep(2000);
exit(0);
}
for(int i = 0; i < 5; i++)
{
throwDice(diceResult);
fiveDices[i] = diceResult;
cout << fiveDices[i] << ' ';
}
}
void throwDice(int& diceResult)
{
srand(time(NULL));
diceResult = 1 + (rand() % 6);
}
When I run the program it only display 1 1 1 1 1 or 5 5 5 5 5 or 3 3 3 3 3 etc. driving me nuts!
Thankfull for any help.