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.

1) Dice is the plural. Dices is chopping vegetables into small cubes.

2) Reread your information about srand(). Is it supposed to be where you have it?

Works now!
Thanks alot for the fast answers, and for the english class!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.