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;
}
|