Create a C program that simulate rolling a die 100 times The
Solution
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
srand ((unsigned int)time(0));
int times_rolled;
int rolled;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
int num6 = 0;
cout <<\"How many times would you like to roll the dice?\" << endl;
cin >> times_rolled;
for (int i = 0; i < times_rolled; ++i)
{
rolled = rand() % 6 + 1;
if (rolled = 1)
{
num1++;
}
else if (rolled = 2)
{
num2++;
}
else if (rolled = 3)
{
num3++;
}
else if (rolled = 4)
{
num4++;
}
else if (rolled = 5)
{
num5++;
}
else if (rolled = 6)
{
num6++;
}
}
cout <<\"#Rolled \\t #Times \\t %Times\" << endl;
cout <<\"----- \\t ------- \\t -------\" << endl;
cout <<\" 1 \\t \" << num1 << \"\\t \" ;
cout <<\" 2 \\t \" << num2 << \"\\t \";
cout <<\" 3 \\t \" << num3 << \"\\t \"
cout <<\" 4 \\t \" << num4 << \"\\t \" ;
cout <<\" 5 \\t \" << num5 << \"\\t \" ;
cout <<\" 6 \\t \" << num6 << \"\\t \" ;
system(\"PAUSE\");
return 0;
}

