#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setw;
using std::setprecision;
using std::fixed;
using std::showpoint;
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"<<setprecision(6)<<showpoint<<((num0/(num0+num1+num2+num3+num4+num5+num6))<<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;
}
At the end of my code why is my showpoint and setprecision not working, it does not display the trailing 0's I need.
You don't have a floating point number. You also have a syntax error there that will keep the code from compiling, so I wonder if this is the actual code you're using. You probably want std::fixed rather than std::showpoint if you want all the output to be the same length.
No. num0 and crew need not be doubles, and should not be doubles given the things they represent and the way you use them. What needs to be a floating point number is the result of the division and we can achieve that by making one of the numbers a double or float. I did it the way I did because: