Just wanted to know, I'm just doing a little dice rolling thing thats storing dice values according to how many times they come up every so often, just wondering if instead of making 50 lines of code doing
if(sum==1)
{
ones+=1;
}
else if(sum==2)
{...
and so on,
I'm thinking of arrays and stuff but cant come up with anything, I like my code to be short and effective, I HATE if-thens if used like I have it above and would like to use a more clever way.
Manutebecker
0
Junior Poster in Training
Recommended Answers
Jump to PostJust wanted to know, I'm just doing a little dice rolling thing thats storing dice values according to how many times they come up every so often, just wondering if instead of making 50 lines of code doing
if(sum==1)
{
ones+=1;
}
else if(sum==2)
{...
and so on,
I'm thinking …
Jump to Postyup yup of course in that case, if you ever computed a sum of 12 (two 6's), numInstances[sum] would actually be out of bounds (no error though, so be careful). So...you would have to store it in array index sum-1 in this case. Also remember that numInstances[0] would actually never …
All 7 Replies
VernonDozier
2,218
Posting Expert
Featured Poster
n1337
29
Junior Poster in Training
VernonDozier
commented:
Good catch! :)
+5
VernonDozier
2,218
Posting Expert
Featured Poster
CoolGamer48
65
Posting Pro in Training
VernonDozier
2,218
Posting Expert
Featured Poster
CoolGamer48
65
Posting Pro in Training
VernonDozier
2,218
Posting Expert
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.