recursion?

Hello,

I am trying to figure out how to print out a schedule for a 8 player tournament. We have a golf league at work that has 8 players. Each player must play one another only once. I have done some research and taken a guess it probably will use permutation or recursion. I am very new to C++ and thought this would be a fun exercise, boy was I wrong. I am stumped, I am not sure where to begin. If any one could point me in the right direction, I would appreciate it.
Thanks for your time,
Brad
Forget about recursion or permutation as they are not related.

Instead, have you solved this problem on paper? If not, do that first. Then you can code that solution.
While you can solution by yourself, you must not depended on the computer!
Meanwhile the problem is just a easy problem that you can solve it quickly if you had learned the math!
If you just want to print out all the possible combinations of games then use something like the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;

int main(){
   const int players_num=8;
   string players[] = {"pl1", "pl2", "pl3", "pl4", "pl5", "pl6", "pl7", "pl8"};
   for(int i=0; i<players_num; i++){
      for(int y=i+1; y<players_num; y++){
         cout << players[i] << " vs " << players[y] << '\n';
      }
   }
}

The first for loop will go through all the players. The second one will go to the player after the "i" is untill the last player. So you will have all the possible cobinations of 2 players without repeating the same combiation.

Hope that helps
Last edited on
thanks for all the reply's. I will try to figure it out on paper. Mitsakos, thanks for the code. I guess I should of stated that the tournament is 7 weeks, so I was trying to output matches for each week.
Like week 1:
1-2
3-4
5-6
7-8
Week 2:
...


thanks again,
brad
Topic archived. No new replies allowed.