Thread: help

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    help

    i just got started with programming and my prof gave me an assignment for Monday.please i need your help.to write and program in c,that takes ten teams and each team comprises of 6 players.write a program that will shuffle each player of each team to play against another player of each time at least once on a particular day.and i need help with this particular source code or a sample so i know what i have to do

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Welcome fabrice!

    Well first post your attempt and then trust me there are many people here able and willing to help you.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    That sounds like a build of a triangular array, and that's more than a beginner's code, imo. Maybe by late November though...

    If a triangular array is what you need, you can start out with two nested for loops, one for each team. The inner for loop will start with one team number greater than the outer team number (or letter).

    Then the two players will have their own two nested for loops, inside the above two - one for each team's players. Here, the inner for loop will begin with zero, since you want player 1 to play against player 1 from the opposing team:

    Code:
    for each team1 
       for each team2 above team2 in number //avoid team1 plays team1
            print out team names: team 1 vs. team 2
            for each player1   starting with zero
                for each player2, starting with zero
                       print out p1 vs. p2 numbers
                print newline
            end for each player1 
            print newline
       end of each team2
    end for each team1
    The above gives you a tapering array print out sorted by team vs team, and then by the individual players match ups. It looks "odd", but it's right.

    I don't know if that's what you want to do or not. I've never heard of anyone doing this, in a programming forum.

    This is an example of the output, for 3 teams, named "A" through C, with 6 numbered players 1 - 6

    Code:
    Teams: A vs. B:
    1 vs 1  1 vs 2  1 vs 3  1 vs 4  1 vs 5  1 vs 6  
    2 vs 2  2 vs 3  2 vs 4  2 vs 5  2 vs 6  
    3 vs 3  3 vs 4  3 vs 5  3 vs 6  
    4 vs 4  4 vs 5  4 vs 6  
    5 vs 5  5 vs 6  
    6 vs 6  
    
    Teams: A vs. C:
    1 vs 1  1 vs 2  1 vs 3  1 vs 4  1 vs 5  1 vs 6  
    2 vs 2  2 vs 3  2 vs 4  2 vs 5  2 vs 6  
    3 vs 3  3 vs 4  3 vs 5  3 vs 6  
    4 vs 4  4 vs 5  4 vs 6  
    5 vs 5  5 vs 6  
    6 vs 6  
    
    Teams: B vs. C:
    1 vs 1  1 vs 2  1 vs 3  1 vs 4  1 vs 5  1 vs 6  
    2 vs 2  2 vs 3  2 vs 4  2 vs 5  2 vs 6  
    3 vs 3  3 vs 4  3 vs 5  3 vs 6  
    4 vs 4  4 vs 5  4 vs 6  
    5 vs 5  5 vs 6  
    6 vs 6
    It looks like player 1 plays more matches than anyone else, but they all play the same number of matches.

    Is this what you need for output, however?

Popular pages Recent additions subscribe to a feed