Computing.Net > Forums > Programming > C++ Random numbers

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ Random numbers

Reply to Message Icon

Name: Rebecca
Date: September 30, 2003 at 15:00:04 Pacific
OS: WinXP
CPU/Ram: ...
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: September 30, 2003 at 16:32:37 Pacific
Reply:

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).


0

Response Number 2
Name: Don Arnett
Date: September 30, 2003 at 16:34:35 Pacific
Reply:

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.


0

Response Number 3
Name: Rolos
Date: September 30, 2003 at 22:19:42 Pacific
Reply:

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



0

Response Number 4
Name: Rebecca
Date: October 2, 2003 at 17:08:23 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ Random numbers

c++ random numbers www.computing.net/answers/programming/c-random-numbers/4776.html

C++ random numbers www.computing.net/answers/programming/c-random-numbers/12193.html

C++ random number generating code? www.computing.net/answers/programming/c-random-number-generating-code/11612.html