Vector help

This program that I am confused on is supposed to use a vector of integers to keep up with rolls of a five dice. It should roll the five dice and store the sum of the dice in the vector using the push_back() function. It should then continue rolling the dice until it rolls a 5 of a kind. Insert that final roll into the vector, and then use a loop to compute the sum and average of the elements in the vector. The output should include: the number of rolls it took to get 5 of a kind and the average value of a roll. NOTE: the program should have two functions: (1) a function that sums 5 integers. (Use it to compute the sum of the 5 dice you roll) and (2) a function that returns a bool to determine if the roll is 5 of a kind. Below are function prototypes for the functions:

int sum5(int n1, int n2, int n3, int n4, int n5);
bool fiveOfAKind(int n1, int n2, int n3, int n4, int n5);

Please help THANKS
Start your homework by writing the implementation of those functions. They are really simple.
I got it.

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
#include <iostream> 
#include <vector> 
#include <stdlib.h> 
#include <time.h> 
using namespace std; 

int sum5(int n1, int n2, int n3, int n4, int n5) 
{ 
	return n1+n2+n3+n4+n5; 
} 

bool fiveOfAKind(int n1, int n2, int n3, int n4, int n5) 
{ 
	return (n1==n2 && n1==n3 && n1==n4 && n1==n5); 
} 

int main() 
{ 
	srand(time(NULL)); 
	vector<int> diceRoll; 
	int n1=1,n2=2,n3=3,n4=4,n5=5; 
	
while(!fiveOfAKind(n1,n2,n3,n4,n5)) 
{ 
	n1 = rand()%6 +1; 
	n2 = rand()%6 +1; 
	n3 = rand()%6 +1; 
	n4 = rand()%6 +1; 
	n5 = rand()%6 +1; 
	diceRoll.push_back(sum5(n1,n2,n3,n4,n5)); 
} 

int sumRoll = 0; 
float avgRoll; 

for(int i=0;i<diceRoll.size();i++) 
{ 
	sumRoll += diceRoll[i]; 
} 
avgRoll = sumRoll*1.0/diceRoll.size(); 

cout<<"Number of rolls : "<<diceRoll.size()<<endl; 
cout<<"Average value per roll : "<<avgRoll<<endl; 

} 
Topic archived. No new replies allowed.