Thread: Football team league need help to make this work

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    5

    Football team league need help to make this work

    Code:
    // 2nd part footy.cpp : Defines the entry point for the console application.
    
    
    #include "stdafx.h"
    #include "string.h"
    #include "stdlib.h"
    #define num_teams 4
    
    int menu();	// prototypes for functions to be called by main
    void enterteams();
    void enterresults();
    void printteams();
    void leagueTeams();
    //File*leagueTeams;
    typedef struct			
    { 
    	char name[4];
    	int played;
    	int won;
    }team;
    team Teams[num_teams];
    //once the array has been populated ,you can write the information to a file:
    voidwriteFiles()
    {
    	leagueTeams=fopen("c:\\C Assignment\\teams.dat","wb");
    	fwrite(Teams,sizeof(team),num_teams,leagueTeams);
    	fclose(leagueTeams);
    }
    void readFiles(team Teams[])
    {
    	leagueTeams=fopen("c:\\C Assignmemt\\teams.dat","rb");
    	if (leagueTeams == NULL)
    	{
    		printf("File cannot be opened\a\n");
    		exit(0);
    		{
    		fread(Teams,sizeof(team),num_teams,leagueTeams);
    		fclose(leagueTeams);
    		}
    {
    	char name[20];
    	int played;
    	int won;
    	int drawn;
    	int lost;
    	int goalsFor;
    	int goalsAgainst;
    	int totalPoints;
    	int take_team_input();
        int take_team_name();
        char hometeam[4],awayteam[4];
    
    	
    } team;				
    
    team teams[12];	
    
    
    {
    char hometeam[4],awayteam[4];
    int x,validteam;
    do
    {
    	validteam = 0;
    	printf("\nPlease enter the home team:");
    	gets(hometeam);
    
    	for(x = 0; x<num_teams;x++)
    	{
    		if(strcmp(hometeam,Teams[x].name) ==0)
    			validteam == 1;
    	}
    	if(!validteam)
    		printf("\nTeam name not valid,please re-enter\n");
    }while(!validteam);
    do
    {
    	validteam = 0;
    	printf("\nPlease enter the away team:");
    	gets(awayteam);
    
    	for(x = 0; x<num_teams;x++)
    	{
    		if(strcmp(awayteam,Teams[x].name) ==0)
    			validteam == 1;
    	}
    	if(!validteam)
    		printf("\nTeam name not valid,please re-enter\n");
    }while(!validteam);
    
    
    int main (void)			/* main calls menu() and this returns the option choice
    						   to the user.  Dependant on that choice, main() will call
    						   enterteams(), enterresults(),enterfixtures() or printteams(), or exit the program
    						   This will continue, once the three functions have finished
    						   their work until the user chooses option 4 - EXIT */
    {
    	int menuChoice;
    	do
    	{
    		menuChoice = menu();            // function is called and returns a value to menuChoice
    		if (menuChoice == 1)
    			enterteams();
    		if  (menuChoice == 2)
    		    enterresults();
    		else if (menuChoice == 3)
    		    printteams();
    	}while (menuChoice != 4);
    	system("pause");
    	return 0;
    }
    
    int menu()					           // offers choices to the user
    {
    	int choice;
    
    	system("cls");			           // clear screen
    
    	printf("\t\t\tMENU\n\t\t\t----\n\n");
    	printf("\t\t1.\tEnter Teams\n");
    	printf("\t\t2.\tEnter Results\n");
      	printf("\t\t3.\tDisplay current Table\n");
    	printf("\t\t4.\tExit\n\n");
    	printf("\t\tPlease enter choice: ");
    	scanf("%d", &choice);
    
    	return choice;
    }
    
    
    void enterteams()        //allows input of match fixtures
    {
    	
    	int x;
    	//char line[30];
    	system("cls");			// clear screen
    	for (x = 0; x < 4; x++)	
    	{
    		// scanf() only accepts one name-- so we use can use sscanf + gets()   
    		printf("Enter details for Teams %d\n\n",(x + 1)); 
    		printf("Name: ");
    		fflush(stdin);
    		gets(teams[x].name);		   
    		/*printf("Played: ");
    		scanf("%d", &teams[x].played);
    		printf("Won: ");
    		scanf("%d", &teams[x].won);
    		printf("Drawn: ");
    		scanf("%d", &teams[x].drawn);
    		printf("Lost: ");
    		scanf("%d", &teams[x].lost);
    		printf("Goals For: ");
    		scanf("%d", &teams[x].goalsFor);
    		printf("Goals Against: ");
    		scanf("%d", &teams[x].goalsAgainst);
    		printf("Total Points: ");
    		scanf("%d", &teams[x].totalPoints);
    		printf("Opposition: ");
    		scanf("%s", &teams[x].opposition);
    		printf("\n");*/
    
    	}
    }
    void enterresults()
    {
    	int x,y,hometeam,awayteam;
    	for (x = 0; x < 4; x++)
    		for (y =x+1; y <4; y++)
    		{
    			printf("Enter result for match between team %s and team %s: ", teams[x].name, teams[y].name);
    			scanf("%d %d", &hometeam, &awayteam);
    			teams[x].played++;
    			teams[y].played++;
    			teams[x].goalsFor = hometeam+teams[x].goalsFor;
    			teams[y].goalsFor= awayteam + teams[y].goalsFor;
    			teams[x].goalsAgainst = hometeam+teams[x].goalsAgainst;
    			teams[y].goalsAgainst = awayteam+ teams[y].goalsAgainst;
    			if ( hometeam == awayteam)
    			{
    				teams[x].totalPoints++;
    				teams[y].totalPoints++;
    			}
    			if  (hometeam>awayteam)
    			{
    				teams[x].totalPoints+1;
    			}
    		    if  (hometeam<awayteam)
    			{
    				teams[y].totalPoints+1;
    			}
    		}
    }
    
    void printteams()
    {
    int x;
    system("cls");			// clear screen	
    	
    	printf("|--------------------------------------------------------------------------------\\|\n");
    	printf("| %-20s | %2s | %2s | %2s | %2s | %2s | %2s | %7s |\n", "Name", "P", "W", "D", "L", "F", "A", "Points" );
    	printf("|--------------------------------------------------------------------------------\\|\n");
    
    	for (x = 0; x < 4; x++)
    	{
    	printf("| %-20s | %2d | %2d | %2d | %2d | %2d | %2d | %7d |\n",teams[x].name, teams[x].played, teams[x].won, teams[x].drawn, teams[x].lost, teams[x].goalsFor, teams[x].goalsAgainst, teams[x].totalPoints);
    	}
    	printf("|-----------------------------------------------------------------------------------\\|\n");
    	system("pause");
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    OK spammer - that's enough cross-posting - see your other thread OK?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cant make it work
    By papous27 in forum Linux Programming
    Replies: 0
    Last Post: 03-05-2002, 09:49 PM
  2. Make quicksort work the other way?
    By Nutshell in forum C Programming
    Replies: 4
    Last Post: 01-24-2002, 12:16 PM
  3. DPMI and how to make it work
    By Sunny in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 12-10-2001, 05:16 PM
  4. how do you make the X Y thing work?
    By bluehead in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2001, 04:19 PM
  5. cprog.com game dev. team
    By Generator in forum A Brief History of Cprogramming.com
    Replies: 90
    Last Post: 11-01-2001, 08:42 PM