However, the value is always 2,293,580. This is strange to me because I'm usually only inputting between 1 and 3 for my individual score values. I'm not sure where this large number is coming from. I used the example from v333k to show what was being stored in my array. It shows as going in correctly. So, I'm thinking that something is wrong in my top_score function.
Thanks msh and tabstop for the help. I have the game index starting at 1 because my array is length 21. Starting it at one prompts to user to input the score for Game 1 instead of Game 0. I figured I'm still only taking 20 entries.
Code:
#include <stdio.h>
#include <stdlib.h>
#define RANGE 21
int top_score(int[],int);
int main(void)
{
int points[RANGE];
int game = 0;
int number;
char instring [20];
for (game = 1; game <= 20; game++)
{
printf ("Enter points scored in game number %d", game);
scanf("%d", &points[game]);
printf("Score %d = %d\n", game, points[game]); /*shows what's in my array*/
points [game] = atoi (instring);
number = top_score(points,game);
}
printf ("Highest points scored in a game is %d", number);
}
int top_score (int points2[], int game2)
{
int index;
int highscore;
highscore = points2[0];
for (index = 0; index < game2; index++)
{
if (highscore < points2[index])
{
highscore = points2[index];
}
}
return (highscore);
}