C++ Basketball game

This is a discussion on C++ Basketball game within the C++ Programming forums, part of the General Programming Boards category; Hey all; i'm just wondering if any1 can help me with this basketball score board i've create ... The goal ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    C++ Basketball game

    Hey all;
    i'm just wondering if any1 can help me with this basketball score board i've create ...
    The goal of this is to complete a C++ program that reads from the user

    - The current quarter (1,2,3 or 4)

    - The remaining time to play in this quarter (in min and sec)

    - The score of the home team

    - The score of the away team

    The program should then be able to determine what should be the scoreboard at the end.

    The program should output the scores rounded to the nearest multiple of 5.

    Note that 2.5 should be rounded to 5.

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    well, first you start by including whatever files you need. You'll probably need at least <iostream>, so you can start with this:
    Code:
    #include <iostream>
    Don't worry about needing others. You can always add more later. Next you need to create an entrypoint for your console application. This is always called main and it always returns an int:
    Code:
    int main()
    {
    }
    now you just have to fill that in with your algorithms. Good Luck!
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Figure out how far along in the game it is, for example, 2nd quarter, then do something like this:
    Code:
    visitors_final_score=visitors_current_score * ((4/current_quarter)*time_in_quarter + time_in_quarter/remaining_time)/Total_time_in_game;
    home_final_score=home_current_score * (4/current_quarter)*time_in_quarter + time_in_quarter/remaining_time)/Total_time_in_game;
    (probably too complicated, but you get the idea)

  4. #4
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Here an idea:

    Code:
    class ScoreBoard
    {
    pubic:
    ScoreBoard();
    private:
    int quarter;    // quarter
    int rtiq;          // remaining time in quater
    int hts;         //  home team score
    int ats;        //  away team score
    };
    
    Use the headers #cstdlib and #ctime to get the random numbers needed for your
    final calulations.
    
    seed srand like so:
    
    srand(time(0));
    
    use rand like this:
    
    hts = rand() % 5 + 1;
    
    This is just an idea of what you could do, place all your variables in the private members of a class, then input the data as needed. Try not to have a mass of global variables! Post the code as you go and we can all give you advise as needed, good luck

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by joeprogrammer
    Figure out how far along in the game it is, for example, 2nd quarter, then do something like this:
    Code:
    visitors_final_score=visitors_current_score * ((4/current_quarter)*time_in_quarter + time_in_quarter/remaining_time)/Total_time_in_game;
    home_final_score=home_current_score * (4/current_quarter)*time_in_quarter + time_in_quarter/remaining_time)/Total_time_in_game;
    (probably too complicated, but you get the idea)
    I don't see how this would work... assuming it's the end of the thrid quarter (with no time left in the quarter) and the visitor has 15 points (I'm assuming 30 minute quarters and a two hour game, an that your Total_time_in_game and everything else was in minutes):
    Code:
    visitors_final_score=15*((4/3)*0+0/30)/120;
    that simplifies to
    Code:
    visitors_final_score=15*(1.3333333*0+0/30)/120;
    which then becomes
    Code:
    visitors_final_score=15*(0+0/30)/120;
    and if you can't see the problem by now:
    Code:
    visitors_final_score=15*(0/30)/120;
    of course the program would have bailed out by now, but just to drive it further home:
    Code:
    visitors_final_score=15*(undef)/120;
    =
    Code:
    visitors_final_score=(undef)/120
    oh noes
    Code:
    =visitors_final_score=(undef)
    now, assuming that you mean to use the next quarter if this one is over (same information):
    Code:
    visitors_final_score=15*((4/4)*30+30/30)/120;
    visitors_final_score=15*(1*30+1)/120;
    visitors_final_score=15*31/120;
    visitors_final_score=3.875;
    visitors_final_score=4;
    now that can't possibly be right, seeing as they already have 15 points... unless it's customary to lose 11 points in the last quarter of a basketball game...

    unless I'm missing something... if you were trying to predict how much the final score would be based off time, the formula would be more like:
    Code:
    	final=static_cast<int>(((score/static_cast<double>(timePlayed))*timeLeft)+score);
    Last edited by major_small; 03-09-2006 at 11:08 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    7

    Unhappy Rounding to multiples of 5

    Hey,
    I am also doind this basketball program, but fortunately I have my algorithms correct, and sorry I cant tell you. BUt I do need help with one thing, how do you round the answer to the nearest multiple of 5? I have tried using floor(x), but this only rounds to the whole number. I have been told to try and if.. statement, but I dont know how. Any help would be great.

    Thanx.

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    something like this:
    Code:
    int i=0;
    for( i=0;i<30;i++){     
    if(5*i>number)break;
                                  }
    int dif1=5*i - number;
    int diff2=number-5*(i-1);
    if(diff1<diff2)number=5*i;else number =5*(i-1);

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    You should probably start a separate thread for a separate question.

    I would use % 5 to find out how far from a multiple of 5 your number is, then subtract that value. If the value was 3 or 4 then add 5 as well to round up.

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    7

    re:basketball rounding to 5

    Thakyou so much, i will try this-it sounds right to use modulo, i thought thats how it would go. Now I just have to work out how to write it!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-07-2010, 11:08 PM
  2. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  3. Need a sample program for basketball game
    By Marrah_janine in forum C++ Programming
    Replies: 5
    Last Post: 12-08-2006, 03:07 AM
  4. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

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