我应该写一个程序,让用户被问到有多少学生在课堂上。然后,它要求每个学生的GPA。最后,它应该显示每个GPA分数的学生人数。到目前为止,这是我的,但它似乎并没有正确计数。GPA成绩计划
#include <stdio.h>
int main(void){
int cnt1, cnt2, cnt3, cnt4, student, numofsdts, GPA, GPAFreq[4];
printf("Enter number of students: ");
scanf("%d", &numofsdts);
student = 1;
while(student <= numofsdts){
printf("GPA of student number %d: ", student);
scanf("%d", &GPA);
if(GPA < 1 || GPA > 4){
printf("invalid number \n");
}
else{
student++;
}
if(student == numofsdts + 1)
break;
if(GPAFreq[1])
cnt1++;
else if(GPAFreq[2])
cnt2++;
else if(GPAFreq[3])
cnt3++;
else if(GPAFreq[4])
cnt4++;
}
printf("GPA 1: %d students \n", cnt1);
printf("GPA 2: %d students \n", cnt2);
printf("GPA 3: %d students \n", cnt3);
printf("GPA 4: %d students \n", cnt4);
}
首先 - 定义什么是预期的特德。其次 - 描述发生了什么。然后,用调试器遍历你的代码,以确定事情没有起作用。注意:'c'数组开始@零 – KevinDTimm