Hi Everyone,
at the end of my code you will see it outputs 0 the hold number and the hold number plus 1 up to 6, to the right of these numbers my code states how many times that number appeared.
My problem is instead of it telling me how many times that number appeared I need it to output the probability.
I tried to multiply the times the number appeared by 1/6, but that did not really work.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setw;
using std::setprecision;
int dieRoll();
int humanTurn(int);
int hold, roll, dice, num, num0, num1, num2, num3, num4, num5, num6;
double total;
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;
// dice=(rand() % 6);
cout<<"Score"<<"\t"<<"Estimated Probability"<<endl;
for (total=0; total<roll; total++) // loop as many time as roll input equals
{
do
{
num+=(rand()%6);
if ((rand()%6)==1) //if the dice roll a 1 end turn start over and move to next turn
{
num=0;
break;
}
if (num>=hold) //if the num equals or is greater than hold then start over the count move to next turn
{
break;
}
}
while (num<hold); // if num is less than hold value continue loop
{
if (num==0) num0++;
if (num==hold) num1++;
if (num==hold+1) num2++;
if (num==hold+2) num3++;
if (num==hold+3) num4++;
if (num==hold+4) num5++;
if (num==hold+5) num6++;
}
}
cout<<"0"<<"\t\t"<<num0<<endl;
cout<<hold<<"\t\t"<<num1<<endl;
cout<<hold+1<<"\t\t"<<num2<<endl;
cout<<hold+2<<"\t\t"<<num3<<endl;
cout<<hold+3<<"\t\t"<<num4<<endl;
cout<<hold+4<<"\t\t"<<num5<<endl;
cout<<hold+5<<"\t\t"<<num6<<endl;
return 0;
}