my assignment is:
Create a student GPA average calculator. The program should
prompt the user to enter up to 30 GPAs, which are stored in a
single-dimension array. Each time he or she enters a GPA, the
user should have the option to calculate the current GPA
average or enter another GPA.
my problem is :
my program doesn't ask to calculate current gpa or another gpa otherwise it's all fine and dandy
and it also allows me to enter above 4.0 :/
Code
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
int index=-1,k=0;
int main()
{
char inp[256]=" ";
double gpa[30];
double totalgpa,avegpa;
printf("***** Welcome To GPA Calculator ***** \n");
while(inp[0]!='q')
{
printf("%s%d%s","Enter The Next GPA Value(",index+1,") or Enter q to stop \n" );
gets(inp);
if(inp[0]=='q'|| index==29)
{
break;
}
gpa[++index]=atof(inp);
}
printf("calculating Average GPA...\n" );
for( k=0;k<index+1;k++)
{
totalgpa+=gpa[k];
}
avegpa=totalgpa/(index+1);
printf("%s%f%s%f","Total GPA Is ",totalgpa," Average GPA Is ",avegpa);
getch();
}
//code ends here