Get outcome of a league fixture

Recently been asked to be a part of a C++ group project in Uni. The aim of our group is to be able to generate a football league table from a set number of fixtures.

My section of the work decides who has WON/LOSS/DREW the fixture and pass the number of points to another member of the group.

below is a small summary of the initial logic I am trying to achieve

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include <iostream> 
using namespace std;

/*
*	this will be the information I will be passed
*
*	for (fixture=1; fixture<5; fixture++)
*		{
*		print ([team1] [team1score] : [team2] [team2score])
*		}
*/

 void allocatePoints()
{
int team1points = 0;
int team2points = 0;

	if (team1score > team2score)
		{ 
			team1points = 3pts;
			team2points = 0pts;
		}
	if (team1score < team2score) 
		{ 
			team1points = 0pts;
			team2points = 3pts;
		}
	if (team1score == team2score)
		{ 
			team1points = 1pts;
			team2points = 1pts;
		}
}

foreach (fixture)

{
        allocatePoints();

}


My main thinking is to first get the initial logic of the programme running so this is basically looking for advice on how to improve my code.

Any ideas/tips/help would be greatly appreciated.

Thanks
Each team needs a variable storing its number of points. You need to update that, not some arbitrary variable that is reset to zero everytime you call the function. Also, it would be neat to do this with a struct or class. Do you know either or both of those? That way, you can have a string name (do you know how to use string?) and points total, as well as W/L/D record for each team easily.
I know what they all are in terms of a definition but putting them to good use it still what i am developing in class.

As far as the team names go, that is not really within my hands, as that is with another member of the group i will have to have a talk with him about how he feels he will be handing me the data.

I still have a few weeks left in the module so hopefully when im revising these topics they will become a little more clear to me of how to use them properly.

I will look into detail about trying to implement the class and passing the points variable to the actual team name(string). Hopefully this wont be too difficult. :)
Thanks, this has pointed me in the correct direction. I will upload my changes later for your attention.
Hi @Mats, i feel i have made considerable progress since our last chat. i feel i have implemented some of the changes you mentioned.

Have you any more points, tips or even some sample code to help get me over the finish line??

see my improvements below. i know it is still a work in progress and needs a little tidy up here and there but i think the correct logic is in place.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

/*
* Identifies the Win Loss Draw for each team
*
* This function takes a score, and identifies the outcome 
* of fixture and delegates the points to that team
*
* @param a string containing the name of the team
* @param the number of points to add to the score
* @return true on success, false on failure
*/
void PointsAllocation::CalculateOutcome(Fixture f)
{
	if(f.GetScore1() > f.GetScore2()) //GetScore1 comes from nialls variable

	{
		UpdatePoints(f.GetTeamName1(), 3);
		UpdatePoints(f.GetTeamName2(), 0);
	}

	if(f.GetScore1() < f.GetScore2())
	{
		UpdatePoints(f.GetTeamName1(), 0);
		UpdatePoints(f.GetTeamName2(), 3);
	}

	if(f.GetScore1() == f.GetScore2())
	{
		UpdatePoints(f.GetTeamName1(), 1);
		UpdatePoints(f.GetTeamName2(), 1);
	}
}

/*
* Updates the score for a given team
*
* This function takes a team name, and a score, and updates the table accordingly
*
* @param a string containing the name of the team
* @param the number of points to add to the score
* @return true on success, false on failure
*/
int PointsAllocation::UpdatePoints(char * TeamName, int Points)
{
	// Search for the record TeamName...

	// Oh, I couldn't find that team name
	return(0); // false
	// Update their points

	// I did it...
	return(1); // true

}
Last edited on
I can only see a little snippet of your code here, but I guess it looks fine.

You could add those W/L/D stats at the same time as you do the points allocations (if you want those stats in of course, but they are usually present in a league table).

Have you any more points, tips or even some sample code to help get me over the finish line??


How close to the finish line are you? I mean, are you reading in results and getting the table now? Or where are you at?
A private mail has been sent @mats
Topic archived. No new replies allowed.