注册 登录
编程论坛 C++教室

程序有点小失误但是看不出错在哪里,大神求帮忙

这是我小名 发布于 2017-09-03 21:20, 1726 次点击
#include<stdio.h>
struct Student
{
  int num;
  char name[10];
  float score[2];
};
struct Student st[2];


struct Student input()
{
  int i;
  printf("请输入学生信息:\n");
  for(i=0;i<2;i++)
  scanf("%d %s %f%f",&st[i].num,&st[i].name,&st[i].score[1],&st[i].score[2]);
}

struct Student print()
{
  int i;
  printf("学生信息:\n");
  printf("学号    姓名   成绩1   成绩2 \n");
  for(i=0;i<2;i++)
  {
    printf("%-8d%-7s%-6.2f%-6.2f\n",st[i].num,st[i].name,st[i].score[1],st[i].score[2]);
  }
}

int main()
{
   input();
   print();
   printf("\n");
}
只有本站会员才能查看附件,请 登录
5 回复
#2
zghnxzdcx2017-09-04 10:24
scanf("%d %s %f%f",&st[i].num,&st[i].name,&st[i].score[1],&st[i].score[2]);
两个 %f 之间没有没有分隔,出现一些不可理解的现象属于正常
还有数组下标问题,C(C++)的数组下标是从0还是从1开始,忘了……

[此贴子已经被作者于2017-9-4 10:28编辑过]

#3
yangfrancis2017-09-04 13:58
scanf("%d %s %f%f",&st[i].num,&st[i].name,&st[i].score[1],&st[i].score[2]);
改成
scanf("%d %s %f%f",&st[i].num,&st[i].name,&st[i].score[0],&st[i].score[1]);
后面的printf也要改
#4
这是我小名2017-09-04 13:58
回复 2楼 zghnxzdcx
大神,我根据你的建议改了一下感觉还是错的耶
#5
这是我小名2017-09-04 14:38
回复 3楼 yangfrancis
对啦 ,谢谢大神
#6
zghnxzdcx2017-09-04 22:09
回复 4楼 这是我小名
结构体数组的下表用的0 .和1,分数数组的下标用的1和2……
1