Advertisement
mejpark

C program basketball scores

Jan 13th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. /* This program creates an array of 10 game scores for a basketball player.
  2.    The scores from the first six games are in the program and the
  3.    scores From the last four are inputted by the user.
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. main()
  9. {
  10.     int gameScores[10] = {12, 5, 21, 15, 32, 10};
  11.     int totalPoints = 0;
  12.     int i;
  13.     float avg;
  14.  
  15.     // Only need scores for last 4 games so the loop will cover
  16.     // array elements 6-9
  17.     for (i=6; i < 10; i++)
  18.     {
  19.         // Add one to the array number as the user won't think
  20.         // of the first game as game 0, but game 1
  21.         printf("What did the player score in game %d? ", i+1);
  22.         scanf(" %d", &gameScores[i]);
  23.     }
  24.     // Now that you have all 10 scores, loop through the scores
  25.     // to get total points in order to calculate an average.
  26.  
  27.     for (i=0; i<10; i++)
  28.     {
  29.         totalPoints += gameScores[i];
  30.     }
  31.     // Use a floating-point variable for the average as it is
  32.     // likely to be between two integers
  33.  
  34.     avg = ((float)totalPoints/10);
  35.  
  36.     printf("\n\nThe Player's scoring average is %.1f.\n", avg);
  37.  
  38.     return(0);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement