jeudi 6 avril 2017

How to output two different sets of random numbers in C++?

So far, this is my code:

#include <iostream>
#include <time.h>
#include <stdio.h>      
#include <stdlib.h>  
using namespace std;

int DealerRoll(int dealerRoll)
{
        srand (time(NULL));
    for (int dealerCount = 1; dealerCount <= 3; dealerCount++)
    {
    dealerRoll = rand()% 6+1;
    cout << dealerRoll << " ";
    }
    return dealerRoll;
}
int PlayerRoll(int playerRoll)
{

        srand (time(NULL));
    for (int playerCount = 1; playerCount <= 3; playerCount++)
    {
    playerRoll = rand()% 6+1;
    cout << playerRoll << " ";
    }
    return playerRoll;
}

int main()
{
    int dealerRoll;
    int playerRoll;

    cout << "Dealer's Roll: " << endl;
    DealerRoll(dealerRoll);
    cout << endl << "Your Roll: " << endl;
    PlayerRoll(playerRoll);
system ("pause");
return 0;
}

My problem is that the Dealer and Player's random (dice) roll is always the same. The output would be something like this for example:

Dealer's Roll: 
1 6 3 
Your Roll: 
1 6 3  

How do I make the player's roll different from the dealer's like this?

Dealer's Roll: 
1 6 3 
Your Roll: 
4 2 5




Aucun commentaire:

Enregistrer un commentaire