dice generator question

i am writing a code that generates 5 random dice rolls and checks to see if there are 3 of a kind i am getting an error with the function for the dice roller though the error is error C2661: 'srand' : no overloaded function takes 0 arguments
i have looked at several threads and tried different things still can not get it to work any one have any ideas and also look at my method for checking 3 of a kind
please and thank you

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
39
40
41
42
43
44
45
46
47
48
49
50
//     
//      CPS 216
//      04/08/2014
// this program generates 5 random dice rolls
// then tests to check for three of a kind

#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

// function for dice roll
int dieroll()
{
srand(time(0));
int ran=(srand()%6)+1;
cout << ran << endl;
return ran;
}

//function check three of a kind
bool threeOfAKind(int dA,int dB,int dC,int dD,int dE){
return (((dA==dB)+(dA==dC)+(dA==dD)+(dA==dE))==2||
        ((dB==dA)+(dB==dC)+(dB==dD)+(dB==dE))==2||
        ((dC==dA)+(dC==dB)+(dC==dD)+(dC==dE))==2||);
}

int main()
{
// variables
int r1(0),r2(0),r3(0),r4(0),r5(0);
int three;

// output programs function
cout << "This program generates 5 random dice rolls and checks for 3 of a kind" << endl;
// generate 5 dice rolls
r1=dieroll();
r2=dieroll();
r3=dieroll();
r4=dieroll();
r5=dieroll();
// output the rolls
cout << " your 5 rolls are :" <<r1<<","<<r2<<","<<r3<<","<<r4<<","<<r5<<endl;
three=threeOfAKind(r1,r2,r3,r4,r5)
cout << three;


    return 0;
}
Line 17: You want rand(), not srand().

BTW, srand(time(0)) should only be called once at the beginning of your program. Since srand() resets the random number generator, calling srand on each call to dieroll will always generate the same random number.
thanks got that problem solved and working without the three of a kind , but now i am getting a syntax error in line 26 error C2059: syntax error : ')' i don't see any missing parenthises or extra ones?
Line 26 - I don't see that you need the last logical OR || before that last parenthesis. The compiler may be expecting another condition after that and instead sees a ).
Last edited on
thank you compiling with no errors
new question i added the statement cout <<"there are three of a kind" to the bool function between 23 and 24 and now it comes out saying there are three of a kind every time even when there is not?
Last edited on
That's because any statement between 23 and 24 is executed every time threeOfAKind is called which is before you've evaluated your expression.

Add after line 45:
1
2
  if (three) 
    cout << "You have three of a kind" << endl;

Topic archived. No new replies allowed.