Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ! Kendall Lewis
  2. ! CS 335 - Final Exam - Problem 6
  3. ! 5-7-12
  4.  
  5. PROGRAM test
  6.   IMPLICIT NONE
  7.   INTEGER :: i
  8.   INTEGER :: th
  9.     DO i = 1, 100
  10.       th = throw_dice()
  11.       PRINT*, 'total throw = ', th
  12.     END DO
  13.  
  14.  CONTAINS
  15.    INTEGER FUNCTION throw_dice()
  16.      IMPLICIT NONE
  17.      REAL :: r
  18.      INTEGER :: dice_total
  19.      INTEGER :: throw1, throw2
  20.  
  21.      CALL RANDOM_NUMBER(r)
  22.      throw1 = 1 + NINT(r*5)
  23.      PRINT*, 'throw1 = ', throw1
  24.  
  25.      CALL RANDOM_NUMBER(r)
  26.      throw2 = 1 + NINT(r*5)
  27.      PRINT*, 'throw2 = ', throw2
  28.  
  29.      dice_total = throw1 + throw2
  30.      RETURN
  31.    END FUNCTION throw_dice
  32. END PROGRAM test