我想创建一个程序,通过使用结构来计算学生的结果并打印位置



在这个程序中,我想使用结构获取学生信息并打印位置。在测试部分,只有最好的一个才会数到三。现在,在给出所有输入之后,一切都很好,除了第74行,我在那里添加了所有的标记,但是当我运行代码时,不计算。谁能告诉我问题出在哪里?

#include <stdio.h>
struct student_profile {
char name[100];
int ID[100];
int Final;
int mid;
int attendance;
int assignment;
int quiz1;
int quiz2;
int quiz3;
int total_marks;
} s[100];
int comparison(int quiz1, int quiz2, int quiz3) {
int quiz_best;
if (quiz1 > quiz2 && quiz1 > quiz3) {
printf("Best quiz mark is: n", quiz1);
quiz_best = quiz1;
} else
if (quiz2 > quiz1 && quiz2 > quiz3) {
printf("Best quiz mark is: n", quiz2);
quiz_best = quiz2;
} else {
printf("Best quiz mark is: n", quiz3);
quiz_best = quiz3;
}
return quiz_best;
}
int main() {
int i, n, quiz_best;
printf("Number of students: n");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("nStudent No: %dn", i);
printf("Name: ");
scanf("%99s", s[i].name);
printf("ID: ");
scanf("%99s", s[i].ID);
printf("Final: ");
scanf("%d", &s[i].Final);
printf("mid: ");
scanf("%d", &s[i].mid);
printf("attendance: ");
scanf("%d", &s[i].attendance);
printf("assignment: ");
scanf("%d", &s[i].assignment);
printf("quiz1: ");
scanf("%d", &s[i].quiz1);
printf("quiz2: ");
scanf("%d", &s[i].quiz2);
printf("quiz3: ");
scanf("%d", &s[i].quiz3);
}
printf("n Students Informations:n");
for (i = 0; i < n; i++) {
printf("Student No: %dn", i);
printf("Name: %sn", s[i].name);
printf("ID: %dn", s[i].ID);
printf("Final: %dn", s[i].Final);
printf("mid: %dn", s[i].mid);
printf("attendance: %dn", s[i].attendance);
printf("assignment: %dn", s[i].assignment);
printf("quiz1: %dn", s[i].quiz1);
printf("quiz2: %dn", s[i].quiz2);
printf("quiz3: %dn", s[i].quiz3);
quiz_best = comparison(s[i].quiz1, s[i].quiz2, s[i].quiz3);
printf("The best quiz mark is: %dn", quiz_best);
printf("Total marks: ",quiz_best+ s[i].Final+ s[i].mid+ s[i].assignment+ s[i].attendance );
}
return 0;
}

根本原因

您刚刚在第74行

的printf函数中遗漏了添加格式说明符。解决方案:

将第74行修改如下:

printf("Total marks: %d",quiz_best+ s[i].Final+ s[i].mid+ s[i].assignment+ s[i].attendance );

相关内容

  • 没有找到相关文章

最新更新