Alright, let's narrow it down is the problem:
1) Because the data in the grades array isn't what you need,
or
2) Is the data in the array OK, but the display in the showgrades() function, is not working right?
Shouldn't getgrades have an int return type?