Thread: Need help with "expected expression before"

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

    Question Need help with "expected expression before"

    Code:
    #include <stdio.h>#include <string.h>
    #include <stdlib.h>
    
    
    #define TEAM_NAME 4
    #define MAX_TEAMS 12
    #define NUM_MATCH 198
    #define WEEKDAY_NAME 4
    #define NAMELEN 4
    
    
    /* data from files */
    typedef struct{
        char homet[NAMELEN];
        char awayt[NAMELEN];
        char name[NAMELEN];
        int points;
        int goalsf;
        int goalsa;
        int goals_home;
        int goals_away;
        int goalsd;
        int played;
        int goals_temp;
        int won;
        int won_home;
        int won_away;
        int loss;
        int loss_home;
        int loss_away;
        int tie;
        int tie_home;
        int tie_away;
        double spectator;
        double spectator_temp;
        char weekday;
        int date;
        int month;
        double moment;
    }info;
    
    
     info info_info[NUM_MATCH];
     info read_from_file[NUM_MATCH];
     info team_info[MAX_TEAMS];
    
    
    /************************************************************/
    /*               Hjælpe functione                           */
    /************************************************************/
    void read_from_file_func();
    void total_team_info();
    void score_home(int, int);
    void score_away(int, int);
    void print_func(int);
    void print_header();
    
    
    /************************************************************/
    /*                Opgaverne                                 */
    /************************************************************/
    
    
    void find_match_goals();
    void most_goals();
    void find_the_teams_who_win_most_away_match();
    void less_spectators();
    void find_match_by_time();
    void print_score();
    
    
    
    
    /************************************************************/
    /*                Main Function                             */
    /************************************************************/
    void main(){
        int option = 0;
    
    
        read_from_file_func();
        total_team_info();
    
    
    
    
        while (option != 7){
            print_header();
            switch (option){
    
    
            case 1: /* Display goals over 7 */
                find_match_goals();
                break;
    
    
            case 2: /* Display most goals */
                most_goals();
                break;
    
    
            case 3: /* most win away */
                find_the_teams_who_win_most_away_match();
                break;
    
    
            case 4: /* less_spectators */
                less_spectators();
                break;
    
    
            case 5: /* find_match_by_time */
                find_match_by_time();
                break;
    
    
            case 6: /* print_score */
                print_score();
                break;
    
    
            case 7: /*Exit*/
                printf("\n*** FINISHED ***\n");
                exit(0);
            default: /*invalid option letter entererd*/
                printf("\nInvalid choice, Please try again\n");
            }
        }
        return;
    }
    
    
    /****************************************************************/
    /*                      Read from file                          */
    /****************************************************************/
    void read_from_file_func(){
        int i = 0;
        FILE *ifp;
        ifp = fopen("superliga-2013-2014", "r");
        if (ifp != NULL){        /* File could be opened */
            while (fscanf(ifp, "%s %d %*s %d %lf %s %*s %s %d %*s %d %lf ",
                read_from_file[i].weekday,
                read_from_file[i].date,
                read_from_file[i].month,
                read_from_file[i].moment,
                read_from_file[i].homet,
                read_from_file[i].awayt,
                read_from_file[i].goalsf,
                read_from_file[i].goalsa,
                read_from_file[i].spectator) == 9);
            fclose(ifp);
        }
        else{ printf("kan ikke aabne filen %s\n", "superliga - 2013 - 2014"); }
    
    
        return;
    }
    
    
    /****************************************************************/
    /*                      Make struct of team name                */
    /****************************************************************/
    
    
    void total_team_info(){
        int i = 0, k = 0, j = 0;
    
    
    
    
        for (i = 0; i < (MAX_TEAMS/2); ++i)
        {
            team_info[i+i].homet = info[i].homet;
            team_info[i+i+1].awayt = info[i].awayt
    
    
            for (j = 0; j < NUM_MATCH; ++j)
            {
                while(team_info[i+i].homet == info[j].homet)
                {
                    score_home((i+i),j)
                }
    
    
                while(team_info[i+i].homet == info[j].awayt)
                {
                    score_away((i+i),j)
                }
    
    
                while(team_info[i+i+1].awayt == info[j].homet)
                {
                    score_away((i+i+1),j)
                }
    
    
                while(team_info[i].awayt == info[j].awayt)
                {
                    score_home((i+i+1),j)
                }
            }        
        }
        return;
    }
    
    
    void score_home(i,j){
    
    
        team_info[i].goalsf += info[j].goalsf;
        team_info[i].goalsa += info[j].goalsa;
        team_info[i].goalsd += (info[j].goalsf + info[j].goalsa);
        team_info[i].goals_home += info[j].goalsf;
        team_info[i].spectator += info[j].spectator;
            if (info[i].goalsf == info[j].goalsa){
                team_info[i].played++;
                team_info[i].points++;
                team_info[i].tie_home++;
                team_info[i].tie++;
            }
            else if (info[i].goalsf >= info[j].goalsa){
                team_info[i].won_home++;
                team_info[i].won++;
                team_info[i].played++;
                team_info[i].points += 3;
            }
            else (info[i].goalsa >= info[j].goalsf); {
                team_info[i].loss_home++;
                team_info[i].loss++;
                team_info[i].played++;
            }
    }
    
    
    void score_away(i,j){
        team_info[i].goalsf += info[j].goalsf;
        team_info[i].goalsa += info[j].goalsa;
        team_info[i].goalsd += (info[j].goalsf + info[j].goalsa);
        team_info[i].goals_away += info[j].goalsa;
        team_info[i].spectator += info[j].spectator;
            if (info[i].goalsf == info[j].goalsa){
                team_info[i].played++;
                team_info[i].points++;
                team_info[i].tie_away++;
                team_info[i].tie++;
            }
            else if (info[i].goalsf >= info[j].goalsa){
                team_info[i].won_away++;
                team_info[i].won++;
                team_info[i].played++;
                team_info[i].points += 3;
            }
            else (info[i].goalsa >= info[j].goalsf); {
                team_info[i].loss_away++;
                team_info[i].loss++;
                team_info[i].played++;
            }
    }
    
    
    void print_func(i){
    printf("%s %d %*s %d %lf %s %*s %s %d %*s %d %lf \n",
                    team_info[i].weekday,
                    team_info[i].date,
                    team_info[i].month,
                    team_info[i].moment,
                    team_info[i].homet,
                    team_info[i].awayt,
                    team_info[i].goalsf,
                    team_info[i].goalsa,
                    team_info[i].spectator);
    }
    
    
    /****************************************************************/
    /*                      Print Menu Options                      */
    /****************************************************************/
    void print_header(){
        int a = 0;
        printf("\n****************************");
        printf("\n*     Football League    *");
        printf("\n****************************\n");
        printf("\n1.\tfind_match_goals\n");
        printf("\n2.\tmost_goals\n");
        printf("\n3.\tmost win away \n");
        printf("\n4.\tless_spectators\n");
        printf("\n5.\tfind_match_by_time \n");
        printf("\n6.\tprint_score\n");
        printf("\nPlease Enter Your Choice: \n");
        scanf("%d", &a);
        return;
    }
    
    
    /****************************************************************/
    /*                     1 : find_match_goals                     */
    /****************************************************************/
    void find_match_goals(){
        int i;
        match_score();
    
    
        for (i = 0; i < NUM_MATCH; ++i) {
            if ((team_info[i].goalsd) >= 7) {
                print_func(i);
            }
        }
        return;
    }
    
    
    /****************************************************************/
    /*                    2 : most_goals                            */
    /****************************************************************/
    
    
    void most_goals(){
        int i = 0, j = 0;
    
    
        for (i = 0; i < NUM_MATCH; i++){
            for (j = 0; j < NUM_MATCH - i; j++){
                if (team_info[j].goals_temp<team_info[j + 1].goals_temp){
                    int temp = team_info[j].goals_temp;
                    team_info[j].goals_temp = team_info[j + 1].goals_temp;
                    team_info[j + 1].goals_temp = temp;
                }
            }
        }
    
    
        for (i = 0; i < NUM_MATCH; ++i)
        {
            if (team_info[i].goalsd == team_info[0].goals_temp){
                print_func(i);
                printf("scoret : %d\n\n", team_info[0].goals_temp);
                i = i;
            }
        }
        return;
    }
    /****************************************************************/
    /*                     3 : most win away                        */
    /****************************************************************/
    
    
    void find_the_teams_who_win_most_away_match(){
        int i, j;
        for (i = 0; i < MAX_TEAMS; ++i)
        {
            for (j = 0; j < MAX_TEAMS; ++j)
            {
                
                if (team_info[i].homet == team_info[j].awayt){
                    if (team_info[i].won_home < team_info[j].won_away){
                        printf("Team won more at away match: %c\n", team_info[j].awayt);
                    }
                }
            }
        }
        return;
    }
    
    
    /****************************************************************/
    /*                     4 : less_spectators                      */
    /****************************************************************/
    
    
    void less_spectators(){
        int i = 0, j = 0, k = 0;
    
    
        for (i = 0; i < NUM_MATCH; i++){
            for (j = 0; j < NUM_MATCH - i; j++){
                if (team_info[j].spectator > k){
                    k = team_info[j].spectator;
                    
                }
            }
        }
    
    
        for (i = 0; i < NUM_MATCH; ++i)
        {
            if (team_info[i].spectator_temp == k){
                printf("Team name : %c and spectator: %lf \n", team_info[i].homet, team_info[0].spectator_temp);
            }
        }
        return;
    }
    
    
    /****************************************************************/
    /*                     5 : find_match_by_time                   */
    /****************************************************************/
    
    
    void find_match_by_time(){
        char u;
        int k1, k2, j, i, l;
    
    
        printf("Enter lower time and upper time and a weekday\n");
        scanf("%d.%d %s", &k1, &k2, &u);
    
    
        for (i = 0; i < NUM_MATCH; i++){
            for (j = 0; j < NUM_MATCH - i; j++){
                if (team_info[j].goals_temp < team_info[j + 1].goals_temp){
                    int temp = team_info[j].goals_temp;
                    team_info[j].goals_temp = team_info[j + 1].goals_temp;
                    team_info[j + 1].goals_temp = temp;
                }
            }
        }
    
    
        for (i = 0; i < NUM_MATCH; ++i)
        {
            for (l = 0; l < NUM_MATCH; ++l){
    
    
                if (team_info[l].moment >= k1 && team_info[l].moment <= k2){
                    if ((team_info[l].goalsd == team_info[i].goals_temp) != team_info[i - 1].goals_temp) {
                        print_func(i);
                        printf("scoret : %d\n\n", team_info[i].goals_temp);
                    };
                };
            }
            int getch();
            return;
        }
    }
    
    
        /****************************************************************/
        /*                     6 : print_score                               */
        /****************************************************************/
        void print_score(){
            int i = 0, j = 0;
    
    
    
    
    //sortere team_info
            for (i = 0; i < MAX_TEAMS; ++i){
                    printf("%d : Team name: %s MP: %d MW: %d MT: %d ML: %d GF: %d GA: %d P: %d \n",
                        i,
                        team_info[i].name,
                        team_info[i].played,
                        team_info[i].won,
                        team_info[i].tie,
                        team_info[i].loss,
                        team_info[i].goalsf,
                        team_info[i].goalsa,
                        team_info[i].points);
           }
        return;
    }
    have "expected expression before", error but don't know how to correct them. probably the same error all everywhere.
    Attached Images Attached Images Need help with &quot;expected expression before&quot;-capture-jpg 

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    First of all, the line numbers in the posted code don't match up with your errors. Line 150 in the error message seems to line up with line 173 of the posted code.

    The problem is that you're using 'info' as if it is an object, when it is actually a type. You can't do that.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User coln's Avatar
    Join Date
    Oct 2014
    Location
    In the jungle
    Posts
    1
    Yes. "info" is a type, not an object, where you use it all over the place. Did you mean to use "info_info" instead?

    Also, line 223 in your error code (or line 253 in what you posted) has a ';' at the end of the else block, where there shouldn't be one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 08-09-2012, 12:48 PM
  2. Replies: 9
    Last Post: 03-31-2009, 04:23 PM
  3. Replies: 24
    Last Post: 09-06-2006, 06:17 PM
  4. "expected primary-expression before "else" ???
    By Helix Stark in forum C++ Programming
    Replies: 6
    Last Post: 08-05-2006, 11:04 PM

Tags for this Thread