여기에 학생의 수 (n)에 대한 최고 점수를 알아 내고 학생에게 정보를 표시하는 방법에 문제가 있습니다. 불쾌한 정보에 신경 쓰지 마십시오. 코드가 너무 길어서 죄송합니다. 도움을 주시면 감사하겠습니다. 감사합니다.가장 높은 점수를 얻은 학생 정보가 표시됩니다.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
//Function Prototype
void add(struct student s[]);
void deleting(struct student s[]);
void update(struct student s[]);
void view(struct student s[]);
void calculateAvg(struct student s[]);
void max(struct student s[]);
/*void min(struct student s[]);
void find(struct student s[]);
void sort(struct student s[]);*/
//Size
int size = 0;
//Structure
struct student{
int id;
char name[25];
char sex; // M(Male) || F(Female)
int q1,q2,mid,final,total;
}s[20];
int main()
{
int choice;
system("CLS");
printf("\n==========================");
printf("\n MENU");
printf("\n==========================");
printf("\n1. Add student records");
printf("\n2. Delete student records");
printf("\n3. Update student records");
printf("\n4. View all student records");
printf("\n5. Calculate an average of a selected student’s scores");
printf("\n6. Show student who gets the max total score");
printf("\n7. Show student who gets the min total score");
printf("\n8. Find student by ID");
printf("\n9. Sort records by total scores");
printf("\n10. EXIT!");
printf("\n\n Please enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: add(s);break;
case 2: deleting(s);break;
case 3: update(s);break;
case 4: view(s);break;
case 5: calculateAvg(s);break;
case 6: max(s);break;
/*case 7: min(s);break;
case 8: find(s);break;
case 9: sort(s);break;
case 10: exit(1);break;*/
}
getch();
}
void add(struct student s[])
{
char choice;
int j;
system("CLS");
printf("\nPlease enter student no.%d information below:\n",size+1);
printf("ID : ");
scanf("%d",&s[size].id);
printf("Name : ");
scanf("%s",&s[size].name);
printf("Sex [M=Male||F=Female] : ");
scanf(" %c",&s[size].sex);
printf("Quiz1: ");
scanf("%d",&s[size].q1);
printf("Quiz2: ");
scanf("%d",&s[size].q2);
printf("Mid-term: ");
scanf("%d",&s[size].mid);
printf("Final: ");
scanf("%d",&s[size].final);
++size;
printf("ADD PROCESS COMPLETE!");
printf(" SIZE=%d",size);
printf("\nPRESS (R) TO RETURN, PRESS (A) TO ADD: ");
scanf(" %c",&choice);
if (choice == 'R' || choice == 'r')
main();
else if (choice == 'a' || choice == 'A')
add(s);
getch();
}
void deleting(struct student s[])
{
int num,i,j,flag=0;
char choice;
system("CLS");
printf("Please enter student ID to delete: ");
scanf("%d",&num);
for (i=0; i<size; ++i)
{
if (s[i].id == num)
{
for (j=i; j<size; ++j)
{
s[j] = s[j+1];
}
--size;
flag=1;
break;
}
}
if (flag==1)
printf("DELETE PROCESS IS DONE!");
else if (flag==0)
printf("ERROR!!");
printf("\nPRESS (R) TO RETURN, PRESS (D) TO DELETE: ");
scanf(" %c",&choice);
if (choice == 'R' || choice == 'r')
main();
else if (choice == 'D' || choice == 'd')
deleting(s);
getch();
}
void update(struct student s[])
{
int i,num,flag=0;
char choice;
system("CLS");
printf("Please enter student ID to update: ");
scanf("%d",&num);
for (i=0; i<size; ++i)
{
if (s[i].id == num)
{
flag=1;
printf("\nStudent no.%d information:\n",i+1);
printf("ID:%d |",s[i].id);
printf("Name:%s |",s[i].name);
printf("Sex:%c |",s[i].sex);
printf("Quiz1:%d |Quiz2:%d |Mid-term:%d |Final:%d |",s[i].q1,s[i].q2,s[i].mid,s[i].final);
printf("\n\nPlease enter new inforamtion to update: \n\n");
printf("ID : ");
scanf("%d",&s[i].id);
printf("Name : ");
scanf("%s",&s[i].name);
printf("Sex [M=Male||F=Female] : ");
scanf(" %c",&s[i].sex);
printf("Quiz1: ");
scanf("%d",&s[i].q1);
printf("Quiz2: ");
scanf("%d",&s[i].q2);
printf("Mid-term: ");
scanf("%d",&s[i].mid);
printf("Final: ");
scanf("%d",&s[i].final);
break;
}
}
if (flag==1)
printf("UPDATE PROCESS IS DONE!");
else if (flag==0)
printf("ERROR!!");
printf("\nPRESS (R) TO RETURN, PRESS (U) TO UPDATE: ");
scanf(" %c",&choice);
if (choice == 'R' || choice == 'r')
main();
else if (choice == 'U' || choice == 'u')
update(s);
getch();
}
void view(struct student s[])
{
char choice;
//system("CLS"); may be added if wanted.
for (int j=0; j<size; ++j)
{
printf("\nStudent no.%d information:\n",j+1);
printf("ID:%d |",s[j].id);
printf("Name:%s |",s[j].name);
printf("Sex:%c |",s[j].sex);
printf("Quiz1:%d |Quiz2:%d |Mid-term:%d |Final:%d |",s[j].q1,s[j].q2,s[j].mid,s[j].final);
}
printf("\n\nSIZE=%d",size);
printf("\nPRESS (R) TO RETURN :");
scanf(" %c",&choice);
if (choice == 'R' || choice == 'r')
main();
getch();
}
void calculateAvg(struct student s[])
{
int i,total,flag=0,num;
char choice;
system("CLS");
printf("Please enter student ID to calculate average of marks: ");
scanf("%d",&num);
for (i=0; i<size; ++i)
{
if (s[i].id == num)
{
s[i].total = s[i].q1 + s[i].q2 + s[i].mid + s[i].final;
printf("\n\n Student no.%d information:\n",i+1);
printf("ID:%d |",s[i].id);
printf("Name:%s |",s[i].name);
printf("Sex:%c |",s[i].sex);
printf("Quiz1:%d |Quiz2:%d |Mid-term:%d |Final:%d |",s[i].q1,s[i].q2,s[i].mid,s[i].final);
printf("\n\n TOTAL = %d",s[i].total);
printf("\n AVERAGE = %d",s[i].total/4);
flag=1;
}
break;
}
if (flag==1)
printf("\n\nAVERAGE CALCULATED!");
else if (flag==0)
printf("ERROR!!");
printf("\nPRESS (R) TO RETURN :");
scanf(" %c",&choice);
if (choice == 'R' || choice == 'r')
main();
getch();
}
void max(struct student s[])
{
int i,max;
s[i].total = s[i].q1 + s[i].q2 +s[i].mid + s[i].final
max = s[0].total;
for (i=0; i<size; ++i)
{
if (s[i].total > max)
{
max = s[i].total;
}
}
printf("\nHighest total score is %d belongs to student ID (%d)",max,)//\\problem
}
* ** 디버거 ***를 사용하십시오. 그리고 두 번째 줄에 누락 된 세미콜론을 포함하여 구문 오류가있어'max()'가 컴파일되지 않고 마지막 printf 호출에 대한 인수 목록을 완성하지 못하는 문제가 있습니다. 코드 벽을 게시하려면 (a)하지 말고 (b) (a)를 무시하면 컴파일해야합니다. – WhozCraig
선생님, max()를 제거하면 컴파일되고 내 문제는 max() 뿐이므로 프로그램을 자르지 않으려 고합니다. – Seraj