well tell us what parts you dont understand?
Code:
#include <stdio.h>
#include <string.h>
#define NOOFTEAMS 10
#define STRINGLENGTH 30
#define NOOFGAMES 90
struct team
{
char teamName[STRINGLENGTH];
int points;
int noOfGames;
int matchesPlayed[90];
};
struct leagueTable
{
int noOfTeams;
struct team lgTbl[NOOFTEAMS];
};
struct game
{
char homeTeam[STRINGLENGTH];
char awayTeam[STRINGLENGTH];
int homeGoals;
int awayGoals;
};
struct matchesTable
{
int noOfGames;
struct game mtchTbl[NOOFGAMES];
};
int displayMenu(void);
struct leagueTable initialise(struct leagueTable leagueTeam);
struct leagueTable doAction(int option, struct leagueTable leagueTeam);
struct matchesTable addMatch(struct matchesTable teamGame);
void showHistory(struct matchesTable teamGame);
void displayAll(struct leagueTable leagueTeam);
int main(void)
{
struct leagueTable leagueTeam;
int option;
leagueTeam.noOfTeams = initialise(leagueTeam);
while((option = displayMenu()) !=4)
{
leagueTeam = doAction(option, leagueTeam);
}
return 0;
}
struct leagueTable initialise(struct leagueTable leagueTeam)
{
struct leagueTable leagueTeam;
char teamName[NOOFTEAMS][STRINGLENGTH];
int count;
leagueTeam.noOfTeams = 0;
for(count = 0; count < NOOFTEAMS; count++)
{
printf("Enter team name: ");
gets(teamName[count]);
fflush(stdin);
};
return leagueTeam;
}
int displayMenu(void)
{
int option;
printf("\n\nFootball League Program\n\n");
printf("1\tAdd Match\n");
printf("2\tShow History\n");
printf("3\tShow League\n");
printf("4\tExit\n\n");
printf("Select: ");
while(scanf("%d", &option) !=1 || option < 1 || option > 4)
{
fflush(stdin);
printf("ERROR - MUST be number 1 to 3: ");
}
fflush(stdin);
return option;
}
struct leagueTable doAction(int option, struct leagueTable leagueTeam)
{
switch(option)
{
case 1 : leagueTeam = addMatch(leagueTeam);
break;
case 2 : showHistory(leagueTeam);
break;
case 3 : displayAll(leagueTeam);
break;
}
return leagueTeam;
}
struct matchesTable addMatch(struct matchesTable teamGame)
{
struct team leagueTeam
printf("Enter home team name: ");
gets(teamGame.mtchTbl[teamGame.noOfGames].homeTeam);
fflush(stdin);
printf("Enter away team name: ");
gets(teamGame.mtchTbl[teamGame.noOfGames].awayTeam);
fflush(stdin);
printf("Enter home team goals scored: ");
scanf("%d", &teamGame.mtchTbl[teamGame.noOfGames].homeGoals);
fflush(stdin);
printf("Enter away team goals scored: ");
scanf("%d", &teamGame.mtchTbl[teamGame.noOfGames].awayGoals);
fflush(stdin);
if(teamGame.mtchTbl[teamGame.noOfGames].homeGoals > teamGame.mtchTbl[teamGame.noOfGames].awayGoals)
{
leagueTeam.lgTbl[leagueTeam.noOfTeams].points + 2;
}
else if(teamGame.mtchTbl[teamGame.noOfGames].homeGoals < teamGame.mtchTbl[teamGame.noOfGames].awayGoals)
{
leagueTeam.lgTbl[leagueTeam.noOfTeams].points - 1;
}
else if(teamGame.mtchTbl[teamGame.noOfGames].homeGoals == teamGame.mtchTbl[teamGame.noOfGames].awayGoals)
{
leagueTeam.lgTbl[leagueTeam.noOfTeams].points + 1;
}
else
{
(printf"work out how to show points +3");
}
teamGame.noOfGames++;
return teamGame;
}
void showHistory(struct matchesTable teamGame)
{
int indx;
printf("Enter team name for history search: ");
gets(teamGame.mtchTbl[teamGame.noOfGames].homeTeam);
for(indx = 0; indx < teamGame.noOfGames; indx++)
{
printf("\nAway Team: %s", teamGame.mtchTbl[teamGame.noOfGames].awayTeam);
printf("\nHome goals scored %d", &teamGame.mtchTbl[teamGame.noOfGames].homeGoals);
printf("\nAway goals scored %d", teamGame.mtchTbl[teamGame.noOfGames].awayGoals);
}
}
void displayAll(struct leagueTable leagueTeam)
{
int indx;
for(indx = 0; indx < leagueTeam.noOfTeams; indx++)
{
printf("\n%s", leagueTeam.lgTbl[indx].teamName);
printf("\n%d", leagueTeam.lgTbl[indx].noOfGames);
printf("\n%d", leagueTeam.lgTbl[indx].points);
}
}