I have trying to write this code for days now with little success.
I am trying to create a code that will simulate a roll of the dice.
The hold number is the minimum number that needs to be reached and the probability has to be displayed after each count.
Please any help is 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
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
int dieRoll();
int humanTurn(int);
int hold, roll;
int main()
{
srand(time(0));
cout<<"Enter the amount to hold"<<endl;
cin>>hold;
cout<<""<<endl;
cout<<"enter how many times to roll"<<endl;
cin>>roll;
cout<<""<<endl;
const int MIN_NUMBER=hold, MAX_NUMBER=hold+6;
int num;
cout<<"Score"<<"\t"<<"Estimated Probability"<<endl;
for (num=MIN_NUMBER; num <= MAX_NUMBER;num=(rand() % 6))
cout<<num<<"\t\t"<<"probability"<<endl;
return 0;
}
|
Also here are some examples of the code output when it is working properly.
Example Runs (User input has been bolded and underlined for emphasis.)
What value should we hold at? 17
Hold-at-N turn simulations? 10000000
Score Estimated Probability
0 0.570301
17 0.114186
18 0.108193
19 0.083909
20 0.062619
21 0.040803
22 0.019988
What value should we hold at? 21
Hold-at-N turn simulations? 2
Score Estimated Probability
0 0.000000
21 0.500000
22 0.000000
23 0.500000
24 0.000000
25 0.000000
26 0.000000
What value should we hold at? 21
Hold-at-N turn simulations? 4
Score Estimated Probability
0 0.250000
21 0.250000
22 0.250000
23 0.250000
24 0.000000
25 0.000000
26 0.000000