使用函数计算学生的最终成绩

时间:2015-09-19 09:16:12

标签: c

我的任务:

学生最终成绩的计算考虑公式:FG = 3分配的10%+出勤率的10%+ 3个短测验的15%+ 3个项目的15%+长测验的20%+ 30%的专业考试。显示最终成绩和相应的评论。

要求:

允许用户重复操作或终止程序

备注:

90 - 100    Very Good

80-89       Good

70-79       Fair

60-69       Poor

Below 60    Needs Improvement

我的计划:

int average(int,int,int)

int a1,a2,a3,p1,p2,p3,s1,s2,s3,t1,l1,m1,FG;

intmain()

{

printf(" enter 3 assignments grade:  ");  scanf("%d%d%d",&a1,&a2,&a3);

printf(" enter 3 projects grade:   ");  scanf("%d%d%d",&p1,&p2,&p3);

printf(" enter 3 short quiz:     "); scanf("%d%d%d",&s1,&s2,&s3);

printf(" enter attendance:   "); scanf("%d",&t1);

printf(" enter long quiz grade:  "); scanf("%d",&l1);

printf(" enter major exam:   "); scanf("%d",&m1);

FG= average(a1,a2,a3,p1,p2,p3,s1,s2,s3,t1,l1,m1)

if((FG>=90) && (FG<=100))

printf("remark is VERY GOOD",FG);

if((FG>=80) && (FG<=89))

printf(" remark is GOOD",FG);

if((FG>=70) && (FG<=79))

printf(" remark is FAIR",FG);

if((FG>=60) && (FG<=69))

printf(" remark is POOR",FG);

printf(" [E]xit");

choice=getche();

switch(choice)

{

case 'e': 

case 'E': return 0;

default: printf(" press [E] to exit or press any key to repeat ");

getch();

main();
}

getch();

return 0;

}

void average( float a1, float a2, float a3, float p1, float p2, float p3, float s1, float s2,float s3,float t1,float l1, float m1)

{

return (((a1 + a2 + a3)/3)*.10) + (((p1 + p2 + p3)/3)*.15) + (((s1 + s2 + s3)/3)*.15) + (t1*.10) + (l1*.20) + (m1*.30);

}

问题和问题:

  • 错误发生在statement missing ; in function main

  • 错误发生在type mismatch in redeclaration of average

  • 我的公式是让平均值和函数调用正确吗?

1 个答案:

答案 0 :(得分:-1)

这是我制作的修改后的程序,它有效:)

int average(int,int,int,int,int,int,int,int,int,int,int,int);

int a1,a2,a3,p1,p2,p3,s1,s2,s3,t1,l1,m1,FG;

char choice;

int main()

{

clrscr();

printf(" enter 3 assignments grade: ");

scanf("%d%d%d",&a1,&a2,&a3);

printf(" enter 3 projects grade: ");

scanf("%d%d%d",&p1,&p2,&p3);

printf(" enter 3 short quizzes grade: ");

scanf("%d%d%d",&s1,&s2,&s3);

printf(" enter attendance grade: ");

scanf("%d",&t1);

printf(" enter long quiz grade: ");

scanf("%d",&l1);

printf(" enter major exam grade: ");

scanf("%d",&m1);

FG= average(a1,a2,a3,p1,p2,p3,s1,s2,s3,t1,l1,m1);

if((FG>=90) && (FG<=100))

printf("your remark is VERY GOOD",FG);

if((FG>=80) && (FG<=89))

printf("your remark is GOOD",FG);

if((FG>=70) && (FG<=79))

printf("your remark is FAIR",FG);

if((FG>=60) && (FG<=69))

printf("your remark is POOR",FG);

if(FG<60)

printf("your remark is NEEDS IMPROVEMENT",FG);

printf("\ndo you want to [E]xit?");

choice=getche();

switch(choice)

  {

    case 'e':

    case 'E': return 0;

    default: printf("invalid choice, press any key to repeat");

    getch();

    main();

  }

getch();

return 0;

}

int average(int a1,int a2,int a3,int p1,int p2,int p3,int s1,int s2,int s3,int 
t1,int l1,int m1)

{

return ((((a1 + a2 + a3)/3)*.10) + (((p1 + p2 + p3)/3)*.15) + (((s1 + s2 + s3)/3)*.15) + (t1*.10) + (l1*.20) + (m1*.30));

}
顺便说一下,谢谢你的回答! :)它刷新了我的心灵呵呵:)