Thread: Help! (Beginner)

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    13

    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!

    Thanks in advance

    Valdo!

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    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.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    13
    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

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    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.
    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]
    put your code here
    [/code]
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help for a beginner
    By kiz in forum C Programming
    Replies: 5
    Last Post: 09-19-2007, 08:09 AM
  2. Beginner Help
    By Myst1caL in forum C Programming
    Replies: 4
    Last Post: 09-08-2007, 12:33 PM
  3. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM
  4. beginner ?
    By braincrash in forum C Programming
    Replies: 2
    Last Post: 02-18-2003, 03:33 AM