菜鸟问话: 数据始终输不进去(Turbo C),?????
main(){
struct student
{
char name[10];
float score[3];
};
int i,j;
struct student stud[5];
for(j=0;j<5;j++)
{
printf("\nname:");
gets(stud[j].name);
for(i=0;i<3;i++)
{
printf("\nscore%d:",i);
scanf("%f",&stud[j].score[i]);
}
}
for(j=0;j<5;j++)
printf("\n%s,%f,%f,%f",stud[i].name,stud[j].score[0],stud[j].score[1],stud[j].score[2]);
getch();
}
----------------解决方案--------------------------------------------------------
main()
{
struct student
{
char name[10];
float score[3];
};
int i,j;
float f;
struct student stud[5];
for(j=0;j<5;j++)
{
printf("\nname:");
gets(stud[j].name);
for(i=0;i<3;i++)
{
printf("\nscore%d:",i);
scanf("%f",&f),stud[j].score[i]=f;
}
}
for(j=0;j<5;j++)
printf("\n%s,%f,%f,%f",stud[i].name,stud[j].score[0],stud[j].score[1],stud[j].score[2]);
getch();
}
----------------解决方案--------------------------------------------------------
#include <stdio.h> #include <conio.h>
int main() { struct student { char name[10]; float score[3]; }; int i,j; struct student stud[3]; for(j=0;j<3;j++) { printf("\nname:"); gets(stud[j].name); for(i=0;i<3;i++) { printf("\nscore%d:",i); scanf("%f",&stud[j].score[i]); fflush(stdin); } } for(j=0;j<3;j++) printf("\n%s,%f,%f,%f",stud[j].name,stud[j].score[0],stud[j].score[1],stud[j].score[2]); return 0;
}
----------------解决方案--------------------------------------------------------
你们见过这样的结构体么?
struct student
{
char name[10];
float score[3];
};
----------------解决方案--------------------------------------------------------