home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REXXCH03.ZIP / GAME.CMD < prev    next >
OS/2 REXX Batch file  |  1991-03-12  |  3KB  |  85 lines

  1. /* This is a scoreboard for a game.  Any number of      */
  2. /* players can play.  The rules for scoring are these:  */
  3. /*                                                      */
  4. /* Each player has one turn and can score any number of */
  5. /* points;  fractions of a point are not allowed.  The  */
  6. /* scores are entered into the computer and the program */
  7. /* replies with                                         */
  8. /*                                                      */
  9. /*      the average score (to the nearest hundredth of  */
  10. /*                           a point)                   */
  11. /*      the highest score                               */
  12. /*      the winner        (or, in the case of a tie,    */
  13. /*                           the winners)               */
  14.  
  15. /*------------------------------------------------------*/
  16. /* Obtain scores from players                           */
  17. /*------------------------------------------------------*/
  18. say "Type the score for each player in turn.  When all"
  19. say "have been typed, enter a blank line!"
  20. say
  21. n=1
  22. do forever
  23.   say "Please type the score for player "n
  24.   pull score.n
  25.   select
  26.     when datatype(score.n,whole) then n=n+1
  27.     when score.n="" then leave
  28.     otherwise say "The score must be a whole number."
  29.   end
  30. end
  31.  
  32. n = n - 1                 /* now n = number of players  */
  33. if n = 0 then exit
  34. /*------------------------------------------------------*/
  35. /* compute average score                                */
  36. /*------------------------------------------------------*/
  37. total = 0
  38. do player = 1 to n
  39.    total = total + score.player
  40. end
  41.  
  42. say "Average score is",
  43.     format(total/n,,2,0) /* format "total/n" with       */
  44.                          /*   no leading blanks,        */
  45.                          /*   round to 2 decimal places */
  46.                          /*   do not use exponential    */
  47.                          /*   notation                  */
  48.  
  49. /*------------------------------------------------------*/
  50. /* compute highest score                                */
  51. /*------------------------------------------------------*/
  52. highest = 0
  53. do player = 1 to n
  54.    highest = max(highest,score.player)
  55. end
  56. say "Highest score is" highest
  57.  
  58. /*------------------------------------------------------*/
  59. /* Now compute:                                         */
  60. /*  * W, the total number of players that have a score  */
  61. /*    equal to HIGHEST                                  */
  62. /*  * WINNER.1, WINNER.2 ... WINNER.W, the id-numbers   */
  63. /*    of these players                                  */
  64. /*------------------------------------------------------*/
  65. w = 0                   /* number of winners            */
  66. do player = 1 to n
  67.    if score.player = highest then do
  68.       w = w + 1
  69.       winner.w = player
  70.    end
  71. end
  72.  
  73. /*------------------------------------------------------*/
  74. /* announce winners                                     */
  75. /*------------------------------------------------------*/
  76. if w = 1
  77.    then say "The winner is Player #"winner.1
  78. else do
  79.    say "There is a draw for top place.  The winners are"
  80.    do p = 1 to w
  81.       say "     Player #",winner.p
  82.    end
  83. end
  84. say
  85.