# having a little trouble with my program

Printable View

• 09-16-2012
Kacikae Whitney
having a little trouble with my program
I am a beginner and arrays/functions are giving me a bit of trouble. I a trying to find the highest midterm score and highest final score and pass it back from the function and print. I am also trying to pass the results back as an array. Can anyone help?

Code:

```#include <stdio.h> #include <stdlib.h> int high(int result, int scores[10][2]); int main() {     int highScore[2]; /* equivalent to two variables to hold the maximums */     /* declare array - the first column contains the midterm scores, the second column contains the final scores */     int scores[10][2] = {{78, 90}, {87, 88}, {65, 70}, {56, 100}, {74, 72},         {33, 47}, {87, 88}, {73, 73}, {79, 83}, {95, 89}};     high(highScore [2], scores[10][2]);         printf("Highest midterm score: %d\n", highScore[0]);     printf("Highest final score: %d\n", highScore[1]);     system("pause");     return 0; } /* end of main function */ int high(int result[2], int scores[10][2]) {     for (int i = 0; i < 10; i++)     {         if (scores[i][0] > result[0])         {             result[0] = scores[i][0];         }     }         for (int i = 0; i < 10; i++)     {         if (scores[i][1] > result[1])         {             result[1] = scores[i][1];         }     }   return result[2]; }```
• 09-16-2012
WaltP
You need to initialize highscore to 0 otherwize, the junk that just happens to be in the values may be higher than the high scores.

It also helps us to have an explanation of what you need help with, and why you think you need help. Just saying "HELP" doesn't give us a clue what in direction you need help.
• 09-16-2012
Kacikae Whitney
getting back to u
Quote:

Originally Posted by WaltP
You need to initialize highscore to 0 otherwize, the junk that just happens to be in the values may be higher than the high scores.

It also helps us to have an explanation of what you need help with, and why you think you need help. Just saying "HELP" doesn't give us a clue what in direction you need help.

I need to check to see if I a sending to and returning from the function correctly. Is the way I have my function going to return both the high midterm and final score?
• 09-16-2012
WaltP
No. You cannot return an array. But because you passed the array into the function, whatever you do to the array will be there when you return. This does not happen normally to single variables, though.
• 09-16-2012
Kacikae Whitney
thanks
Thank you! I wasn't sure.