Very stuck on this problem. I FINALLY got the average to come out, but it gives it as negative 32 million or something. Here is my code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float fArray[30];
int choice = 0;
int x = 0;
float total = 0;
float avg = 0;
printf("1. Calculate GPA Average");
printf("\n2. Enter GPA");
printf("\n3. Quit");
printf("\n\nEnter your choice (1-3): ");
scanf("%d", &choice);
if(choice == 2)
{
printf("\n\nEnter GPA: ");
scanf("%.2f\n\n", &fArray[x]);
total = total + fArray[x];
}
else if(choice == 3)
{
return 0;
}
else if(choice == 1)
{
printf("The average is: %f", total / x);
}
for(x = 1; x < 30; x++)
{
fflush(stdin);
int temp = 0;
printf("1. Calculate GPA Average");
printf("\n2. Enter GPA");
printf("\n3. Quit");
printf("\n\nEnter your choice (1-3): ");
scanf("%d", &temp);
if(temp == 2)
{
printf("\n\nEnter GPA: ");
scanf("%.2f\n\n", &fArray[x]);
}
else if(temp == 3)
{
break;
}
else if(temp == 1)
{
printf("The average is: %f", total / x);
}
}
system("pause");
}