How to resolve “parameter has incomplete type” error?

后端 未结 2 1217
后悔当初
后悔当初 2021-01-29 09:47

I\'m a newbie and I need help with debugging my code. When I compile it \'type of formal parameter 1 is incomplete\' and type of formal parameter 2 is incomplete\' error appears

2条回答
  •  深忆病人
    2021-01-29 10:14

    #include 
    struct date {
        int month[1];
        int day[1];
        int year[1];
    
    };
    
    int calc_age (struct date birth, struct date current);
    
    
    int main(void)
    {
    struct date birth, current;
    char c;
    
    printf("Input the birthdate (MM/DD/YY): ");
    scanf("%d %c %d %c %d", birth.month, &c, birth.day, &c, birth.year);
    printf("Input date to calculate (MM/DD/YY): ");
    scanf("%d %c %d %c %d", current.month, &c,  current.day, &c, current.year);
    
    printf("Age is %d years.\n", calc_age(birth, current));
    
    return 0;
    
    }
    
    int calc_age (struct date birth, struct date current) {
    int age;
    
    if (birth.month[0] < current.month[0]) {
        age = (current.year[0] - birth.year[0]);
    } else if (birth.month[0] > current.month[0]) {
        age = (current.year[0] - birth.year[0] - 1);
    } else {
        if (birth.day[0] <= current.day[0]) {
            age = (current.year[0] - birth.year[0]);
        } else {
            age = (current.year[0] - birth.year[0] - 1);
        }
    }
    
    return age;
    }
    

    You should define the struct before main

提交回复
热议问题