# Help! (Beginner)

• 03-20-2012
Valdo
Help! (Beginner)
Hello guys,

I've got a Darts program at the moment and it calculates how many throws were needed to go from 301 to 0.

I need to work out how to calculate the average of game frequency (how many games ended in 7 darts, how many games ended in 8 darts).

I've got my game in a for loop so I can make it play 100 times I just don't know how to make it calculate the frequency averages!

Valdo!
• 03-20-2012
oogabooga
You could have an int array initialized to zero of a size big enough to hold the maximum number of darts that will ever be thrown. Then after each game, increment the element corresponding to the number of darts it took.
Code:

int numDarts[20] = { 0 };

for (game = 1; game <= 100; game++) {
// play the game; let's say that nDarts has the number of darts it took

if (nDarts >= 20)
cout << "numDarts array overflowed: " << game << ", " << nDarts << "\n";
else
numDarts[nDarts]++;
}

// print out numDarts array

Since this is C++, you may want to use a vector instead.
• 03-20-2012
Valdo
Would I have this inside my while loop? Is there any way I could send you my code I think I might be going wrong somewhere...

Thanks alot
• 03-20-2012
oogabooga
Quote:

Would I have this inside my while loop?
I can't see your while loop from here, but I suspect that it corresponds to the for loop in my example.
Quote:

Is there any way I could send you my code
It can't be that long (even a few hundred lines is not too much). Just post it here. Put it in between code tags like this:

[code]