main
p8ltm3pah 2 years ago
parent 60986ec175
commit ed99c543bc

80
3

@ -1,80 +0,0 @@
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
struct Student {
int student_id;
float math_score;
float physics_score;
float english_score;
float total_score;
float average_score;
};
void print_menu() {
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
}
int main() {
struct Student students[3];
int choice;
int i;
while (1) {
print_menu();
printf("Please enter your choice: ");
scanf("%d", &choice);
if (choice == 1) {
printf("Please input info of the three students:\n");
for (i = 0; i < 3; i++) {
printf("Student %d information:\n", i + 1);
printf("Student ID (5-digit natural number): ");
scanf("%d", &students[i].student_id);
printf("Math Score (2-digit integer, 1 decimal place): ");
scanf("%f", &students[i].math_score);
printf("Physics Score (2-digit integer, 1 decimal place): ");
scanf("%f", &students[i].physics_score);
printf("English Score (2-digit integer, 1 decimal place): ");
scanf("%f", &students[i].english_score);
// Calculate total and average score
students[i].total_score = students[i].math_score + students[i].physics_score + students[i].english_score;
students[i].average_score = students[i].total_score / 3.0;
// Print student info
printf("%d,%.1f,%.1f,%.1f\n", students[i].student_id, students[i].total_score, students[i].average_score);
}
} else if (choice == 2) {
for (i = 0; i < 3; i++) {
printf("%d,%.1f,%.1f,%.1f\n", students[i].student_id, students[i].total_score, students[i].average_score);
}
} else if (choice == 3) {
// Sort students based on total score (ascending order)
for (i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if (students[i].total_score > students[j].total_score) {
struct Student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
// Print sorted student info
for (i = 0; i < 3; i++) {
printf("%d,%.1f,%.1f\n", students[i].student_id, students[i].total_score, students[i].average_score);
}
} else if (choice == 4) {
printf("You are about to Quit\n");
break;
} else {
printf("Wrong input\n");
}
}
return 0;
}
Loading…
Cancel
Save