adding contents of an array
I have this program i'm working on and i'm suppose to input some grade averages and then calculate the avg what I'm trying to do first is just add all the GPAs but it won't work can someone tell me why heres the code
Code:
#include <stdio.h>
#include <stdlib.h>
void CalculateAvg(void);
int i;
float iGpa[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int main()
{
int iChoice = 0;
while (iChoice != 3)
{
printf("\n\tGPA Calculator\n");
printf("1\tCalculate Average\n");
printf("2\tEnter new GPA\n");
printf("3\tQuit\n");
printf("\n\n\tEnter a choice: ");
scanf("%d",&iChoice);
if(iChoice == 1)
{
system("cls");
CalculateAvg();
}
if(iChoice == 2)
{
printf("\n\tGPA Calculator\n");
printf("\tEnter a GPA: ");
scanf("%f",&iGpa[i]);
}
}
}
void CalculateAvg()
{
float x;
int i;
for (i = 0; i <= 30; i++)
x += iGpa[i];
printf("The average is %f\n",x);
}