Simple Dice Game Problem

Hello everyone. The program I've written's purpose is to roll a dice 6000 times, and then output the number of times that the dice landed on three. However, the output is saying that out of the 6000 rolls, three was only generated 0 or 1 times. I'm assuming the problem involves my use of srand, and rand, but I can't figure out what is wrong. This is being done on Xcode. Does anyone know what the reason for this is? Much appreciated.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include <iostream>
#include <math.h>
#include <cstdlib>

using namespace std;

const int MAX = 6000;

int main()
{
    cout<<"Shane Skillpa    -     CPSC-146     -      Dice Rolls"<<endl;
    
    int diceRoll = 0;
    int numThrees;
    int i;
    
    
    numThrees = 0;
    srand( (unsigned int) time(NULL) );
    
    for(i=0 ; i < MAX ; i++)
        diceRoll = 1 + rand () % 6;
    
    if(diceRoll == 3)
        numThrees += 1;
    
    
    cout<<numThrees<<" threes were generated in "<< MAX << " rolls"<<endl;
    

    
    cout<< "<<<<<<<NORMAL TERMINATION>>>>>>>"<<endl;
    
    return 0;
    
}
Last edited on
Your if statement isn't inside the for loop.
You sir, are my hero. I can't believe I didn't notice that. Thank you so much.
It happens.

Good luck!
Topic archived. No new replies allowed.