成绩输出不应该用%s,应该是%d
你确定你编译运行了吗?
#include <stdio.h>
#define NAME_SIZE (20)
struct student {
int id;
char name[NAME_SIZE];
int score;
};
struct student a = {201, "zhangsan", 88};
struct student b = {202, "lisi", 99};
int main()
{
if (a.score > b.score) {
printf("学号: %d\n姓名: %s\n成绩: %d\n", a.id, a.name, a.score);
} else if (b.score > a.score) {
printf("学号: %d\n姓名: %s\n成绩: %d\n", b.id, b.name, b.score);
} else {
printf("学号: %d\n姓名: %s\n成绩: %d\n", a.id, a.name, a.score);
printf("学号: %d\n姓名: %s\n成绩: %d\n", b.id, b.name, b.score);
}
}
···shell
root@seven:/projects/Debug# g++ test.cpp -o test/projects/Debug# ./test
root@seven:
学号: 202
姓名: lisi
成绩: 99
```
并没有问题