There are 3 students in a class,now I invoke StuInfo(struct Student *p) to get the information of these 3 students including IDs, names and their scores. I invoke Rank(struct Student *p) to rank their scores and output the best one's information. But,everytime, the output of q->scores is 0.00000 and I don't know why.
here is the code:
#include<stdio.h>
struct Student
{
int number;
char name[20];
double scores;
};
void StuInfo(struct Student *p);
void Rank(struct Student *p);
int main()
{
struct Student stus[3];
struct Student *p;
p=stus;
StuInfo(p);
Rank(p);
return 0;
}
void StuInfo(struct Student *p)
{
printf("please enter the student'ID,name,scores:");
for(int i=0;i<3;i++)
{
scanf("%d%s%f",&(p+i)->number,&(p+i)->name,&(p+i)->scores);
}
}
void Rank(struct Student *p)
{
struct Student *q;
q=p;
for(int i=0;i<2;i++)
{
if(q->scores<(p+i+1)->scores)
{
q=p+i+1;
}
}
printf("the best student's ID%d,name%s,score%f",q->number,q->name,q->scores);
}