Why My C program got error???
这是题目:
---------------------------------------------------------------------
Write an interactive C program which will process test, assignment and final exam marks for the Java programming course. Full marks for test is 20%, assignment 20% and final exam is 60%. Enter the students name and their marks for the continuous assessment above repetitively. The marks’ grade are shown in the table below:
Grade marks
A 80-100
B+ 75-79
B 70-74
B- 65-69
C+ 60-64
C 55-59
C- 50-54
D 40-49
E 35-39
F 0-34
(a) Count and display total number of students
(b) For each assignment, test and final exam component, which have been obtained by the class, determine:
• Total marks for assignment, total marks for test and total marks for final exam
• Average marks for assignment, total marks for test and total marks for final exam
For every student, display the following information:
(i) Student name, total marks for assignment, test and final exam for every student (marks over hundred)
(ii) Mark’s grade Use array concept to solve the problem above.. Make sure the labels for output are clear.
---------------------------------------------------------------------
这是我的答案:
#include<stdio.h>
#include<string.h>
#define no 2
main()
{
int i,test[no],assign[no],exam[no],total_marks[no];
char stud_name[no],grade[no];
int total_test=0;
int total_assign=0;
int total_exam=0;
float ave_assign,ave_test,ave_exam;
clrscr();
for(i=0;i<no;i++)
{ printf("\nStudent's Name > ");
gets(stud_name[i]);
printf("Assignment Marks (20%) > ");
scanf("%d", &assign[i]);
printf("Test Marks (20%) > ");
scanf("%d", &test[i]);
printf("Final Exam Marks (60%) > ");
scanf("%d", &exam[i]);
total_test+=test[i];
total_assign+=assign[i];
total_exam+=exam[i];
total_marks[i]=test[i]+assign[i]+exam[i];
if(total_marks[i]>=80 && total_marks[i]<=100)
strcpy(grade[i],"A");
else if(total_marks[i]>=75 && total_marks[i]<=79)
strcpy(grade[i],"B+");
else if(total_marks[i]>=70 && total_marks[i]<=74)
strcpy(grade[i],"B");
else if(total_marks[i]>=65 && total_marks[i]<=69)
strcpy(grade[i],"B-");
else if(total_marks[i]>=60 && total_marks[i]<=64)
strcpy(grade[i],"C+");
else if(total_marks[i]>=55 && total_marks[i]<=59)
strcpy(grade[i],"C");
else if(total_marks[i]>=50 && total_marks[i]<=54)
strcpy(grade[i],"C-");
else if(total_marks[i]>=40 && total_marks[i]<=49)
strcpy(grade[i],"D");
else if(total_marks[i]>=35 && total_marks[i]<=39)
strcpy(grade[i],"E");
else if(total_marks[i]>=0 && total_marks[i]<=34)
strcpy(grade[i],"F");
else
strcpy(grade[i],"Error");
}
ave_test=(float)total_test/no;
ave_assign=(float)total_assign/no;
ave_exam=(float)total_exam/no;
printf("\nTotal Number of Students >> %d",no);
printf("\nTotal Marks for Assignment >> %d",total_assign);
printf("\nTotal Marks for Test >> %d",total_test);
printf("\nTotal Marks for Final Exam >> %d",total_exam);
printf("\n\nAverage Marks for Assignment >> %.2f",ave_assign);
printf("\nAverage Marks for Test >> %.2f",ave_test);
printf("\nAverage Marks for Final Exam >> %.2f",ave_exam);
printf("\n---------------------------------------------------------");
printf("\n no Student Name Assignment Test Exam Total Grade");
printf("\n---------------------------------------------------------");
for(i=0;i<no;i++)
{
printf("\n %d %s %d %d %d %d %s",i+1,stud_name[i],assign[i],test[i],exam[i],total_marks[i],grade[i]);
}
getch();
}
为何当我RUN时,输入第一人的资料后就有问题了,直接就打印答案?