Thread: I require some help, with some if statement inputs and outputs

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    3

    I require some help, with some if statement inputs and outputs

    Hello ive created a football league program that does everything but allow me to update my table with scores, please have a look bellow.

    Code:
    #include <stdio.h>#include <string.h>
    
    
    #define numberofteams 3
    #define numberofgames (numberofteams * (numberofteams - 1))
     
    struct team
    {
            char name[20];
            int points;
            int gamesplayed;
            int gamepoints;
            int played;
            int win;
            int draw;
            int lose;
            
    };
    
    
    struct game
    {
            char hometeam[20];
            char awayteam[20];
            int homegoals;
            int awaygoals;
    };
    
    
    struct leagueTable
    {
            int noOfTeams;
            struct team lgTbl[numberofteams];
    };
    
    
    void cleargames(struct game games[]);
    void enterteamnames(struct team league[]);
    void enterresults(struct team league[], struct game games[]);
    void displayAllResults(struct team league[numberofteams]);
    
    
    
    
    int main(void)
    
    
    {
            struct team league[numberofteams];
            struct game games[numberofgames];
            int choice;
            char stringchoice[3];
            
            cleargames(games);
            
    
    
    do {
    
    
       printf("Welcome to your fantasy football league \n\n"
       
               
              "1) Enter The Team Names \n"
              "2) Enter The Results of Teams - Not Finished \n"
              "3) Show The Whole League Table - displays all names of teams \n"
              "4) Option Four \n"
              "5) Exit \n");
       gets(stringchoice);
       choice = atoi(stringchoice);
      /* atoi converts string to integer*/ 
       
       
       if (choice == 1) 
       {
           
             enterteamnames(league);
       }
       else if (choice == 2) {
       
       enterresults(league, games);
       
       }
       else if (choice == 3) {
       
       displayAllResults(league);
       
                                }
       else if (choice == 4) {}
       else if (choice == 5) {}
       else {
            printf("Invalid Choice\n\n");
            }
    } while (choice != 5);
    
    
    
    
    return 0;
    }
    
    
    void cleargames(struct game games[])
    {
        int i;
        
        for(i = 0; i < numberofgames - 1; i++)
        {
            strcpy(games[i].hometeam, "");
            strcpy(games[i].awayteam, "");
            games[i].homegoals = 0;
            games[i].awaygoals = 0;
        }
        
    }
    
    
    void enterteamnames(struct team league[])
    {
        int i;
        
        for(i = 0; i < numberofteams; i++)
            {
             printf("Team name: ");
             gets(league[i].name);
             league[i].played = 0; 
             league[i].win = 0;
             league[i].draw = 0;
             league[i].lose = 0;
             league[i].points = 0;
            } 
    }
    
    
    void enterresults(struct team league[], struct game games[])
    {
            int i;
            int gamenumber = 0;
            int homenum;
            int awaynum;
            int d;
            
            for(i=0;i < numberofteams; i++)
            {
                
                if(strcmp(games[i].hometeam, "") == 0)
                {
                    gamenumber = i;
                    break;
                }
            }
            
            
        
        printf("Enter The Home Team Name: ");
        gets(games[gamenumber].hometeam);
        
        
        
            for(i=0;i < numberofteams; i++)
                if(strcmp(games[gamenumber].hometeam, league[i].name) == 0)
                    homenum = i;
                    
            for(i=0;i < numberofteams; i++)
                if(strcmp(games[gamenumber].awayteam, league[i].name) == 0)
                    awaynum = i;              
        
        printf("Enter The Away Team Name: ");
        gets(games[gamenumber].awayteam);
        
        printf("Enter The Score of the game ");
        scanf("%d - %d",&games[gamenumber].homegoals, &games[gamenumber].awaygoals);
        fflush(stdin);
    
    
    
    
        printf("\n%d %d", games[gamenumber].homegoals, games[gamenumber].awaygoals);
    
    
          if(games[gamenumber].homegoals > games[gamenumber].awaygoals)
            {
                    league[homenum].win++;
                    league[awaynum].lose++;
            
                    league[homenum].points+=2;
                    league[awaynum].points-=1;
            }
            else if(games[gamenumber].homegoals < games[gamenumber].awaygoals)
            {
                    league[homenum].lose++;
                    league[awaynum].win++;
                    
                    league[homenum].points-=1;
                    league[awaynum].points+=2;
            }
            else if(games[gamenumber].homegoals == games[gamenumber].awaygoals)
            {
                    league[homenum].draw++;
                    league[awaynum].draw++;
                    
                    league[homenum].points++ ;
                    league[awaynum].points++ ;
            }
            
    
    
           
           
    }
    
    
    void displayAllResults(struct team league[numberofteams])
    
    
    {
     
     int d;
     printf("\n\nPremier League Table\n");
     printf("\n---------------------------------------------------\n");
     printf("\t Name     P   W   D   L   Pts\n");
     printf("-----------------------------------------------------\n");
     
     for (d=0;d<numberofteams;d++)
     {  
      printf("%15s %3d %3d %3d %3d %3d\n", league[d].name,league[d].played, league[d].win, league[d].draw,league[d].lose, 
      league[d].points);
     }
    }

  2. #2
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    its this bit that gives me the problem of adding points;

    Code:
     if(games[gamenumber].homegoals > games[gamenumber].awaygoals)
    Code:
            {
                    league[homenum].win++;
                    league[awaynum].lose++;
    
                    league[homenum].points+=2;
                    league[awaynum].points-=1;
            }
            else if(games[gamenumber].homegoals < games[gamenumber].awaygoals)
            {
                    league[homenum].lose++;
                    league[awaynum].win++;
    
                    league[homenum].points-=1;
                    league[awaynum].points+=2;
            }
            else if(games[gamenumber].homegoals == games[gamenumber].awaygoals)
            {
                    league[homenum].draw++;
                    league[awaynum].draw++;
    
                    league[homenum].points++ ;
                    league[awaynum].points++ ;
            }

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    please delete this thread i have sorted the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help in Inputs and outputs
    By keng1135 in forum C Programming
    Replies: 7
    Last Post: 06-08-2012, 02:04 AM
  2. Creating seperate functions for inputs, outputs and calculations?
    By toby2604HASSELB in forum C Programming
    Replies: 3
    Last Post: 10-21-2010, 02:26 AM
  3. How to handle inputs if the user inputs the wrong thing
    By bassist11 in forum C Programming
    Replies: 5
    Last Post: 09-22-2010, 04:28 AM
  4. Binary Inputs and Outputs *Files Questions
    By nicz888 in forum C++ Programming
    Replies: 13
    Last Post: 12-21-2007, 03:17 AM
  5. Require information!!!!
    By sameer in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2002, 06:51 AM