C++ Dice Roll Program

Hello; I was wondering if anyone could assist me with this problem. The end result should look like this:

Roll Testrun 1 Testrun 2 Total
1's 3 <25%> 6<50%> 9

bet on 1!

Basically it displays the amount of times a Dice roll landed on a number for a certain amount of Testruns. Its also supposed to display the percentages, so lets say the user input is 12 rolls, and 1 is rolled 3 times. That is 25 percent. The program does this for values of 1-6 for all testruns and then tallys up the total amount of times a number was rolled and tells the user to bet on the number that was rolled the highest amount of times. This is what I have so far:

using namespace std;
int main () {
srand (time(0));
int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
int roll;
int num;

cout<< "How many rolls per run test run?";
cin>> roll;

for (int run = 1; run <= 4; run++) {
for (int x = 1; x <= roll; x++)
{

num = (1+ rand()%6);
if (num == 1 ) (a++);
if (num == 2 ) (b++);
if (num == 3 ) (c++);
if (num == 4 ) (d++);
if (num == 5 ) (e++);
if (num == 6 ) (f++);
}


cout << "\n 1's: \t" << a;
cout <<"\n 2's: \t" << b;
cout <<"\n 3's: \t" << c;
cout <<"\n 4's: \t" << d;
cout <<"\n 5's: \t" << e;
cout <<"\n 6's: \t" << f;
all you have to do, is take the number rolled (for instance c for 3) and divide that by the total number of dice rolled (roll) and cast it to a double

double percentage = (c/roll)*100;

cout << "\n 3's: \t" << c << "<" << percentage << "%>";

Last edited on
You'll save yourself a bit of bother if you use arrays here.

Your percentage algorithm will be something along the lines of:

(100 / Number of Rolls) * Instance number rolled.

So, in your example above the code:

(100 / 12) * 3 = 25%;
could you give an example of how i could use the arrays to make it so that when the program is run its displayed like (assuming 10 rolls)

ROLL TESTRUN 1 TESTRUN 2 TOTAL
1's 3 <30%> 2 <20%> 5
2's 2 <20%> 1 <10%> 3
3's 2 <20%> 2 <20%> 4
4's 1 <10%> 2 <20%> 3
5's 1 <10%> 2 <20%> 3
6's 1 <10%> 1 <10%> 2

bet on 1!!
Topic archived. No new replies allowed.