I'm working on a simple program that accepts scores from 20 games. It then is supposed to determine which one is the high score and return that to the screen. The program compiles without errors (using Code::Blocks), and it accepts all 20 inputs, however when it comes to returning the top score, it always returns 0. This is regardless of what numbers are entered. I'm thinking that either a number isn't being stored in the points2 array, highscore integer, or isn't being returned to the variable number. Any help would be much appreciated.
Thanks,
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); gets (instring); points [game] = atoi (instring); } number = top_score(points,game); printf ("Highest points scored in a game is %f", number); } int top_score (int points2[], int game2) { int index; int highscore; highscore = points2[0]; for (index = 1; index < game2; index++) { if (highscore < points2[index]) { highscore = points2[index]; } } return (highscore); }



LinkBack URL
About LinkBacks



