This program should simulate the roll of a single die (dice) (1-6) using the C++
ID: 3641035 • Letter: T
Question
This program should simulate the roll of a single die (dice) (1-6) using the C++ random number functions. First ask the user how many times they would like to have the die (dice) rolled. Next, have the program simulate the number of rolls of the die (dice) the user requested and keep track of which number the die (dice) landed on for each roll. At the end of the program print out a report showing how many times the die (dice) roll landed on each number and what percentage of the total times the die (dice) roll landed on each number. Do NOT use functions or arrays on this#include<iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand ((unsigned int)time(NULL));
int times = 0;
int roll;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
int num6 = 0;
int Num1, Num2, Num3, Num4, Num5, Num6;
roll = rand() % 6 + 1;
while(times >= 1)
{
cout << "How many times would you like to roll the dice?";
cin >> times;
}
for (int i = 1; i <= times; roll++)
{
if (roll == 1)
{
num1++;
}
else if (roll == 2)
{
num2++;
}
else if (roll == 3)
{
num3++;
}
else if (roll == 4)
{
num4++;
}
else if (roll == 5)
{
num5++;
}
else if (roll == 6)
{
num6++;
}
}
Num1 = num1/times *100;
Num2 = num2/times *100;
Num3 = num3/times *100;
Num4 = num4/times *100;
Num5 = num5/times *100;
Num6 = num6/times *100;
cout <<"# Rolled # Times % Times" << endl;
cout <<"----- ------- -------" << endl;
cout <<" 1 " << num1 << " " << fixed << setprecision(2) << Num1 << "% ";
cout <<" 2 " << num2 << " " << fixed << setprecision(2) << Num2 << "% ";
cout <<" 3 " << num3 << " " << fixed << setprecision(2) << Num3 << "% ";
cout <<" 4 " << num4 << " " << fixed << setprecision(2) << Num4 << "% ";
cout <<" 5 " << num5 << " " << fixed << setprecision(2) << Num5 << "% ";
cout <<" 6 " << num6 << " " << fixed << setprecision(2) << Num6 << "% ";
system("PAUSE");
return 0;
}