Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have to write a program that has an inputed number of "rolls of the dice" and I am to output how many times say, six of a kind or two triples occur. I know how to do random numbers, but they have to equal the number of rolls, and I don't know how to do that. Can someone help me?

I'm making some assumptions here due to lack of specifics.
I'm guessing that you mean that "one roll" is the rolling of six die (six dice??) and that you need to input a number to specify how many rolls to simulate. In other words, you need to input a number to specify how times the set of six dice will be rolled.
This sounds like a set of nested loops. The inner loop would go six times, once for each die (dice?). The outer loop out go the number of times input (the number of rolls).

I'm not sure if you are asking about this part, but in the inner loop, you'd probably save the six random numbers into either six variables or an array so that you can compare the values to determine if it was six of a kind, two triples, etc.

It seems like you need a for-loop with embedded if loops for this:
for (int i = 0; i < input; i++)
{
if (/*double comparison*/)
DoubleCounter++;
else if (/*six of a kind comparison*/)
SixOfKind_counter++;
}It should repeat the random number process for the number of rolls that the user wants. Now, if you want to keep a track of your doubles and what have you, use counter variables inside of if loops with your comparisons. Then you can take those counter variable values and display them to the user telling them how many times each has occurence came up.
- Rolos

Thanks. I figured it out. I had to save the 6 numbers and compare them to see what event it was. Basically what you guys said, though I am proud to say I figured it out before I checked back here.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |