You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
1.8 KiB

#include <stdio.h>
typedef struct INFO
{
int num;
float Maths;
float Physics;
float English;
float sum;
float average;
}Info;
Info stu[3];
void menu();
void info();
void grade_sort();
int main()
{
menu();
info();
grade_sort();
}
void info()
{
for (int i = 0; i < 3; i++)
{
scanf("%d%f%f%f", &stu[i].num, &stu[i].Maths, &stu[i].Physics, &stu[i].English);
}
}
void menu()
{
for (int i = 0; i < 30; i++)
{
printf(" ");
}
printf("1.Input\n");
for (int i = 0; i < 30; i++)
{
printf(" ");
}
printf("2.Output\n");
for (int i = 0; i < 30; i++)
{
printf(" ");
}
printf("3.Order\n");
for (int i = 0; i < 30; i++)
{
printf(" ");
}
printf("4.Quit\n");
char c;
scanf("%c", &c);
if (c == 'i')
{
printf("Please input info of the three students:\n");
}
else if (c == 'o')
{
printf("You are trying to Output info\n");
}
else if (c == 'm')
{
printf("You are trying to Make things ordered\n");
}
else if (c == 'q')
{
printf("You are about to Quit\n");
}
else{
printf("Wrong input\n");
}
}
void grade_sort()
{
for (int i = 0; i < 3; i++)
{
stu[i].sum = stu[i].Maths + stu[i].Physics + stu[i].English;
stu[i].average = stu[i].sum / 3;
}
for (int i = 0; i < 3; i++)
{
for (int j = 2; j > i; j--)
{
if (stu[j].sum < stu[j - 1].sum)
{
Info tmp = stu[j];
stu[j] = stu[j - 1];
stu[j - 1] = tmp;
}
}
}
for (int i = 0; i < 3; i++)
{
printf("%d,%.1f,%.1f\n", stu[i].num, stu[i].sum, stu[i].average);
}
}