-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice.cpp
More file actions
43 lines (38 loc) · 733 Bytes
/
Copy pathdice.cpp
File metadata and controls
43 lines (38 loc) · 733 Bytes
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int rollDice(int num);
int main()
{
int q, w, r, u;
while(r<u)
{
cin >> q >> w;
cout << "how many times do u want to run it: "<<endl;
cin >> u;
cout << "The number of times the dice are rolled to "
<< "get the sum of " << q << " : "<< rollDice(q) << endl;
cout << "The number of times the dice are rolled to "
<< "get the sum of " << w <<" : "<< rollDice(w) << endl;
r++;
}
return 0;
}
int rollDice(int num)
{
int die1;
int die2;
int sum;
int rollCount = 0;
srand(time(0));
do
{
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
sum = die1 + die2;
rollCount++;
}
while (sum != num);
return rollCount;
}