0

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.

Edited by sellemaster

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by sellemaster
2

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?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.