lzting 发表于 2021-6-20 11:37:50

结构体问题

#include <stdio.h>
struct subjects
{
   int Math;
       int Physic;
       int English;
};

typedef struct subjects subjects;


int main()
{
    int num;
        struct Student
        {
           int ID;
           char name;
           int subjects;
           int ave;
        };
        typedef struct Student Student;
       
        void Dealing( int n , Student *stu1 );

        Student stu;

        scanf("%d",&num);

        Dealing(num,stu);



}

void Dealing( int n , Student *stu1 )
{
    int i,Ave;
        for(i=0;i<n;i++)
        {
                scanf("%d%s%d%d%d",&stu.ID,stu.name,&stu.subjects.Math,&stu.subjects.Physic,&stu.subjects.English);
                Ave = (stu.subjects.Physic + stu.subjects.English +stu.subjects.Math)/3.0;
                stu.ave=Ave;
        }
}


大体思路就是用结构体存放数据,但是格式有问题,不知道哪里出了问题,请帮忙看一下

人造人 发表于 2021-6-20 11:45:25

#include <stdio.h>

struct subjects
{
    int Math;
    int Physic;
    int English;
};

typedef struct subjects subjects;

struct Student
{
    int ID;
    char name;
    //int subjects;
    subjects subjects;
    int ave;
};
typedef struct Student Student;

int main()
{
    int num;

    void Dealing( int n , Student *stu1 );

    Student stu;

    scanf("%d",&num);

    Dealing(num,stu);


    return 0;
}

void Dealing( int n , Student *stu1 )
{
    int i,Ave;
    for(i=0;i<n;i++)
    {
      scanf("%d%s%d%d%d",&stu1.ID,stu1.name,&stu1.subjects.Math,&stu1.subjects.Physic,&stu1.subjects.English);
      Ave = (stu1.subjects.Physic + stu1.subjects.English +stu1.subjects.Math)/3.0;
      stu1.ave=Ave;
    }
}
页: [1]
查看完整版本: 结构体问题