Thread: Need help with a 5-aside football league program

  1. #1
    Registered User
    Join Date
    Mar 2015
    Posts
    1

    Need help with a 5-aside football league program

    Hi, i am a beginner in c programming and I am trying to write a program to keep track of the goals scored by 5 football teams and theire points.A win is worth 3points, a draw is worth 1 point and a loss is zero points .The output should look something like this Need help with a 5-aside football league program-fleague-png
    I can't figure out how to program "played" , goals and points and have them added up each time the program is repeated.

    Here is what I have so far
    If someone could please help me with that "played" , goals and points thing I would be really grateful

    Code:
    #include <stdio.h> int main(void)
    {
        char answer;
        int team[6] = { "1", "2", "3", "4", "5", "6" };
        int hometeam;
        int awayteam;
        int homescore;
        int awayscore;
        int pointhome;
        int pointaway;
        int played = 0;
        int n;
    
    
            do{
    
    
                printf("\n\n");
    
    
                printf("Home team number :");
                scanf_s("%i", &hometeam);
    
    
                printf("\n\n");
    
    
                printf("Away team number :");
                scanf_s("%i", &awayteam);
    
    
                printf("\n\n");
    
    
                printf("Home team score: ");
                scanf_s("%i", &homescore);
    
    
                printf("\n\n");
    
    
                printf("Away team score: ");
                scanf_s("%i", &awayscore);
    
    
                if (homescore > awayscore )
                    pointhome = +3;
                
                else if (homescore < awayscore)
                    pointhome = +0;
                
                else if (homescore = awayscore)
                    pointhome = 1;
                
    
    
                if (awayscore > homescore)
                    pointaway = +3;
    
    
                else if (awayscore < homescore)
                    pointaway = +0;
    
    
                else if (awayscore = homescore)
                    pointaway = 1;
    
    
    
    
                
                printf("\n\n");
    
    
                printf("Team\tGoals for\tGoals against\t\tPoints");
    
    
                printf("\n\n");
    
    
                if (hometeam == 1)
                    printf("Team 1\t\t%i\t\t%i\t\t%i",homescore, awayscore, pointhome);
                else if (awayteam == 1)
                    printf("Team 1\t\t%i\t\t%i\t\t%i",awayscore, homescore, pointaway);
                else printf("Team 1\t\t0\t\t0\t\t0");
    
    
                printf("\n\n");
    
    
                if (hometeam == 2)
                    printf("Team 2\t\t%i\t\t%i\t\t%i", homescore, awayscore, pointhome);
                else if (awayteam == 2)
                    printf("Team 2\t\t%i\t\t%i\t\t%i", awayscore, homescore, pointaway);
                else printf("Team 2\t\t0\t\t0\t\t0");
    
    
                printf("\n\n");
    
    
                if (hometeam == 3)
                    printf("Team 3\t\t%i\t\t%i\t\t%i", homescore, awayscore, pointhome);
                else if (awayteam == 3)
                    printf("Team 3\t\t%i\t\t%i\t\t%i", awayscore, homescore, pointaway);
                else printf("Team 3\t\t0\t\t0\t\t0");
    
    
                printf("\n\n");
    
    
                if (hometeam == 4)
                    printf("Team 4\t%i\t\t%i\t\t%i", homescore, awayscore, pointhome);
                else if (awayteam == 4)
                    printf("Team 4\t%i\t\t%i\t\t%i", awayscore, homescore, pointaway);
                else printf("Team 4\t\t0\t\t0\t\t0");
    
    
                printf("\n\n");
    
    
                if (hometeam == 5)
                    printf("Team 5\t\t%i\t\t%i\t\t%i", homescore, awayscore, pointhome);
                else if (awayteam == 5)
                    printf("Team 5\t\t%i\t\t%i\t\t%i", awayscore, homescore, pointaway);
                else printf("Team 5\t\t0\t\t0\t\t0");
    
    
                printf("\n\n");
    
    
                if (hometeam == 6)
                    printf("Team 6\t\t%i\t\t%i\t\t%i", homescore, awayscore, pointhome);
                else if (awayteam == 6)
                    printf("Team 6\t\t%i\t\t%i\t\t%i", awayscore, homescore, pointaway);
                else printf("Team 6\t\t0\t\t0\t\t0");
    
    
                printf("\n\n");
    
    
                printf("\nPress Y to continue. Press N To Exit : ");
                scanf_s(" %c", &answer);
    
    
                printf("\n\n");
    
    
            } while (answer == 'y' || answer == 'Y');
        }

  2. #2
    Registered User
    Join Date
    May 2013
    Posts
    228
    Hi Doilmilk.
    In the snippet:
    Code:
                if (homescore > awayscore )
    
                    pointhome = +3;
    
                 
                else if (homescore < awayscore)
                    pointhome = +0;
                 
                else if (homescore = awayscore)
                    pointhome = 1;
    The statement
    Code:
    pointhome = +3;
    will not add 3 to pointhome, but rather will overwrite the value in pointhome with 3. What you are looking for is:
    Code:
    pointhome += 3;
    Same goes for assignements 1 and 0; I assume you want to add 1 to the team balance, not overwrite it over and over again...

    Another thing I noticed from the output is that you supposed to print all of the leagues' teams, and not just the ones that got new values, thus I would'nt condition the printf's on the values of 'hometeam' and 'awayteam'.

    Hope that helps...
    Last edited by Absurd; 03-14-2015 at 03:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Football League Program
    By cgod1234 in forum C Programming
    Replies: 4
    Last Post: 01-22-2013, 03:35 AM
  2. How to program a "soccer league fixture"?
    By Awareness in forum C Programming
    Replies: 2
    Last Post: 02-13-2012, 07:58 PM
  3. Replies: 4
    Last Post: 02-26-2009, 08:44 PM
  4. Football team league need help to make this work
    By wurzull in forum C Programming
    Replies: 1
    Last Post: 04-07-2007, 07:35 AM