Programming Project 4
Golf Statistics Keeper
int main() { int scoreList [MAX_PLAYERS]; /* Array to store golf scores */ int numberOfPlayers = 0; /* Total number of scores entered */ float averageScore = 0.0; /* Average golf score */ int winningScore = 0; /* The lowest score */ printf("\nWelcome to CMSC104's Golf Statistics Program!\n\n"); /* Fill array with golf scores */ numberOfPlayers = FillGolfScoreList (scoreList); /* Print the golf scores */ PrintGolfScoreList (scoreList, numberOfPlayers); /* Find and print the winning (lowest) score */ winningScore = FindWinner (scoreList, numberOfPlayers); printf("The winning score was %d.\n\n", winningScore); /* Calculate and print the average golf score */ averageScore = CalculateAverageScore (scoreList, numberOfPlayers); printf("The average score was: %.3f.\n\n", averageScore); /* Find and print the players who had scores below the average */ ProcessBelowAverage (scoreList, numberOfPlayers, averageScore); return 0; }
You MUST use the main() function exactly as it is given. However, you need to add the following code before main:
To use the data file as input to your program, you will use Linux redirection. When you run your program, use the following command:
a.out < scores.dat
You will need to copy the file scores.dat
into your directory.
To do this, go to the directory where you would like to store
scores.dat
. Then, use the following command to copy
scores.dat
into the directory:
cp /afs/umbc.edu/users/d/b/dblock/pub/CS104/Proj4/scores.dat .Notice that the space and period at the end of the command are part of the command.
Here is a example of what the input data file could look like:
76 80 73 74 89 0
You will also find proj4.c
in the directory with
scores.dat
. You can copy it to your own directory
following the above directions.
linux2[3]% gcc -ansi -Wall proj4.c linux2[4]% cat scores.dat 79 88 94 92 83 82 0 linux2[5]% a.out < scores.dat Welcome to CMSC104's Golf Statistics Program! The following scores were entered: Player 1: 79 Player 2: 88 Player 3: 94 Player 4: 92 Player 5: 83 Player 6: 82 The winning score was 79. The average score was: 86.333. The following players received a score below the average: Player # Score ---------- ---------- 1 79 5 83 6 82 linux2[6]%Your output does not have to match the sample exactly, with a few exceptions:
Here is a sample submission command. Note that the project name starts with uppercase 'P'.
submit cs104_0101/0501 Proj4 proj4.c
To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show the file that you submitted in a format similar to the Unix 'ls' command.
submitls cs104_0101/0501 Proj4