这是我在这个网站上发现的一个问题,但回答与我认为我的问题没有直接关系。我有点尴尬,因为我还是个业余爱好者。我在询问用户他们想输入多少个 GPA。然后我要求输入每个索引。问题是每个索引都返回 0。所以我很确定我搞砸了变量类型或者可能是我增加索引的方式。这是一个家庭作业问题,我更多的是寻求指导而不是完全放弃。
#include<stdio.h>
main()
{
char Rspns;
int i, toCount, Total;
float GPA[toCount];
printf("\n\tYou can average up to 30 GPAs.");
printf("\n\tPlease choose how many GPAs you would like to average:");
scanf(" %d" , &toCount);
//assign how many indexes array should have
for(i = 0; i<toCount; i++)
GPA[i] = i++;
do
{
system("cls");
printf("\n\nEnter a GPA:");
scanf(" %f" , &GPA);
printf(" %f" , GPA[i]);
Total += GPA[i];
getch();
system("cls");
printf("\n\n\tWould you like to average the current amount of GPA's?");
printf("\n\nY/N: ");
scanf(" %c" , &Rspns);
if(Rspns == 'y' || Rspns == 'Y')
{
Total = Total / toCount;
printf("The average of those GPAs is %.1f" , Total);
getch();
}// end response
}while(i<=toCount);//end forCount
Total = Total / toCount;
}