Hey guys! I have been using this site for a while now I gotta say, I love it!
I have a question now, though. I am writing a very simple program where a user can input 10 GPA's and then list them in either ascending or descending order. I am running into an issue though. I have tried two different ways so far, but neither seem to be working.
This first way gets the loop that I want, but when the last 'printf' is called, it always displays random numbers...
Code:
main()
{
float iGpa[10];
int x=0;
while (x<10){
printf("Please enter 10 GPA's\n: ", x++);
scanf("%f", &iGpa[x]);
}
printf("%f", iGpa[10]);
}
...And for this one, I get a SEGFAULT error
Code:
main()
{
float iGpa[10];
int x=0;
for(x=0;x<10;x++){
printf("Enter 10 GPA's: ",x++);
scanf("%f", &iGpa[10]);
}
prinf("%f", iGpa[10]);
}
My suspicion is either my code to assign the values into the array is incorrect, of my code to display the array is incorrect, but I can not figure out a which/how.
Also, I am pretty sure I could get it if I assign each GPA to it's own variable, but I would rather a loop for cleaner code.
Any help is greatly appreciated, Thanks!