Need help with a bowling program...

This is a discussion on Need help with a bowling program... within the C++ Programming forums, part of the General Programming Boards category; So I have to calculate the final score for a bowling game with 5 frames. I know how the bowling ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    1

    Need help with a bowling program...

    So I have to calculate the final score for a bowling game with 5 frames. I know how the bowling score system works, but I am little confused on how I should write the code. I know I will have to use some ifs but I don't really know how to start it. Sorry I'm a beginner, any tips?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Figure out how you keep score. If you had to explain to a very patient but dense person how to keep score in bowling, how would you do it? Write down the steps as you would explain them. Make sure that all cases are covered.

    Once you know the logic, coding it is trivial.

    (Also, bonus hint: be sure you know what the input is going to look like -- all numbers, or with 'X' and '/' etc.)

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    I agree with the advice above but i suggest you stick to just using numbers to represent everything on the scorecard at first, graphical representation can come once you have the routine working and know a bit more about writing your code.
    i would use an array for each player with three elements (spaces to store scores) each element will hold the value of the score for each delivery of the ball per frame, (use three elements from the start just to cover the final frame which i believe has max of three shots at the pins)

    here's some example code fragments for ideas.

    Code:
    /*here are some ideas for variables you might need.....*/
    
    /* these are your arrays to hold the score from each delivery of the ball for your player */
    
    int player1[3];
    
    
    /* this holds the score between frames because i believe it is not updated until following frame? * /
    
    int lastframescore1 = 0;     
    
    
    /* this for getting the scores from pins just knocked down latest frame */
    
    int currentframescore1 = 0;
    
    
    /* this are for bonuses from last round(lastframescore) added to currentframescore */
    
    int totalframescore1 = 0;            
    
    
    /* these for the running game totals */
    int totalgamescore1 = 0;
    
    
    /* frame + shot counter */
    
    int frame = 0;
    int shot = 0;
    
    /* variable to hold number of pins knocked over */
    
    int pinsdown = 0;
    
    
    /*Now an example of how you might use those arrays in a game loop */
    
    while(frame < 5)
    {
        
        while(shot < 2)                         /*starts from 0 so 0, then 1 is two shots */
         {
    
     /* your game code to play the shot here, maybe using random number that you can 'weight' favourably or unfavourably depending on the player 'skill' * the result of the play is stored in 'pinsdown = ....' */
    
          player1[shot] = pinsdown;
          lastframescore = lastframescore  + player1[shot];
    
          shot ++;                                   /* shot = shot + 1, i.e next loop */
         
          }
    
    currentframescore = currentframescore + lastframescore; 
    
    shot = 0;                                        /* reset for next loop */
    lastframescore = 0;                        /* reset for next scores */
    
    frame++;
    }
    I have not got time to fill all this in here or use all the variables i listed, but i think you should be able to get some tips from this, good luck!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21