怀念不如相见X 2021-09-25 16:57 采纳率: 100%
浏览 64
已结题

帮们看看这段C的代码 实在不知道怎么改了~

#include<stdio.h>

typedef struct STU
{
    char num[7];
    char name[16];
    struct DATE
    {
        int year;
        int month;
        int day;
    }birthday;
    struct RECORD
    {
        int a;
        int b;
        int c;
        int d;
    }record;
}stu;

void main()
{

int n,i;

scanf("%d",&n);


for(i = 0; i < n; i++)
{    
    scanf("%s %s %d%d%d %d%d%d",&stu[i].num,&stu[i].name,&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day,&stu[i].record.a,&stu[i].record.b,&stu[i].record.c);
/*    scanf("%s",&stu[i].name);
    scanf("%d%d%d",&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day);
    scanf("%d%d%d",&stu[i].record.a,&stu[i].record.b,&stu[i].record.c);*/
}

int rr[n];

for(i = 0; i < n; i++)
{
    rr[i] = a*0.2 + b*0.3 + c*0.5;
}

printf("num       name      birthday    s1  s2  s3  sum\n");

for(i=0 ; i<n; i++)
{
    printf("%-10s",stu[i].num);
    printf("%-10s",stu[i].name);
    printf("%d/%2d/%-4d",stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day);
    printf("%-4d\n",rr[i]);
}

}

错误信息如下;
T.CPP
e:\c\l\t.cpp(33) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(33) : error C2228: left of '.num' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(33) : error C2228: left of '.name' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(33) : error C2228: left of '.birthday' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2228: left of '.year' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(33) : error C2228: left of '.birthday' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2228: left of '.month' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(33) : error C2228: left of '.birthday' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2228: left of '.day' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(33) : error C2228: left of '.record' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2228: left of '.a' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(33) : error C2228: left of '.record' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2228: left of '.b' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(33) : error C2228: left of '.record' must have class/struct/union type
e:\c\l\t.cpp(33) : error C2228: left of '.c' must have class/struct/union type
e:\c\l\t.cpp(39) : error C2057: expected constant expression
e:\c\l\t.cpp(39) : error C2466: cannot allocate an array of constant size 0
e:\c\l\t.cpp(39) : error C2133: 'rr' : unknown size
e:\c\l\t.cpp(43) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
e:\c\l\t.cpp(50) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(50) : error C2228: left of '.num' must have class/struct/union type
e:\c\l\t.cpp(51) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(51) : error C2228: left of '.name' must have class/struct/union type
e:\c\l\t.cpp(52) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(52) : error C2228: left of '.birthday' must have class/struct/union type
e:\c\l\t.cpp(52) : error C2228: left of '.year' must have class/struct/union type
e:\c\l\t.cpp(52) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(52) : error C2228: left of '.birthday' must have class/struct/union type
e:\c\l\t.cpp(52) : error C2228: left of '.month' must have class/struct/union type
e:\c\l\t.cpp(52) : error C2275: 'stu' : illegal use of this type as an expression
e:\c\l\t.cpp(20) : see declaration of 'stu'
e:\c\l\t.cpp(52) : error C2228: left of '.birthday' must have class/struct/union type
e:\c\l\t.cpp(52) : error C2228: left of '.day' must have class/struct/union type
执行 cl.exe 时出错.

  • 写回答

3条回答 默认 最新

  • qzjhjxj 2021-09-25 19:52
    关注

    修改如下,供参考:

    #include<stdio.h>
    typedef struct STU
    {
        char   num[7];
        char   name[16];
        struct DATE
        {
            int year;
            int month;
            int day;
        }birthday;
        struct RECORD
        {
            int a;
            int b;
            int c;
            int d;
        }record;
    }Stu;
    
    Stu stu[100];
    
    int  main()
    {
        int n,i;
        scanf("%d",&n);
    
        for(i = 0; i < n; i++)
        {
            scanf("%s%s%d%d%d%d%d%d",stu[i].num,stu[i].name,&stu[i].birthday.year,
            &stu[i].birthday.month,&stu[i].birthday.day,&stu[i].record.a,&stu[i].record.b,
            &stu[i].record.c);
            //scanf("%s",&stu[i].name);
            //scanf("%d%d%d",&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day);
            //scanf("%d%d%d",&stu[i].record.a,&stu[i].record.b,&stu[i].record.c);
        }
        //int rr[n];
        int *rr = new int[n];
        for(i = 0; i < n; i++)
        {
            //rr[i] = a*0.2 + b*0.3 + c*0.5;
            rr[i] = stu[i].record.a*0.2 + stu[i].record.b*0.3 + stu[i].record.c*0.5;
        }
        printf("num       name      birthday    s1  s2  s3  sum\n");
        for(i=0 ; i<n; i++)
        {
            printf("%-10s",stu[i].num);
            printf("%-10s",stu[i].name);
            printf("%d/%2d/%-4d",stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day);
            printf("%-4d\n",rr[i]);
        }
        
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 12月9日
  • 已采纳回答 12月1日
  • 修改了问题 9月25日
  • 修改了问题 9月25日
  • 展开全部

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器