Lab 9 Questions - Fortran Programming | CSCI 260, Lab Reports of Computer Science

Material Type: Lab; Class: FORTRAN PROGRAMMING; Subject: Computer Science; University: Colorado School of Mines; Term: Spring 2008;

Typology: Lab Reports

Pre 2010

Uploaded on 08/19/2009

koofers-user-l59
koofers-user-l59 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI260 Lab 9 Spring 2009
Due: 11:59 PM., Wednesday, March 25, 2008
Objective: Familiarize yourself with FORTRAN SUBROUTINES and FUNCTIONS.
1. Login to isengard.
2. Change your current working directory to your csci260a directory.
3. Make a lab9 subdirectory and then change directory to your lab9 directory.
4. Copy over the files from the /class/csci260a/Assignments/lab9 directory to your lab9
(current) subdirectory.
5. Use cp to copy and rename the lesson1 shell to mylesson1.f95.
Editing mylesson1.f95
6. Your program should play the dice game called lucky-7. A player starts out with $100
and places how much they wish to bet and on what value set rolled. The pay back for
the bet is 1 to 1 for dice values of 2 – 6, 3 to 1 for dice values of 7 and 1 to 1 for dice
values of 8 to 12. Build a Subroutine that interacts with the user; it should get which
dice values they wish to bet on and how much they wish to bet. If the use ever goes
less that $0 the game should end. The user also has the option to end the game at the
end of each round.
Here is some useful code that you may use in the program.
REAL:: x
::::::::::
CALL RANDOM_SEED
DO
CALL getBet(bet, ch)
CALL RANDOM_NUMBER(x)
d1 = INT(x * 6) +1
CALL RANDOM_NUMBER(x)
d2 = INT(x * 6) +1
:::::::::::
SUBROUTINE getBet(amount, d_values)
IMPLICIT NONE !Must explicitly declare all variables
INTEGER, INTENT(OUT):: amount, d_values
WRITE(*,*)"*****************************************************”
WRITE(*,*)"What range of dice values do you wish to bet on?"
WRITE(*,*)"1. For 1 - 6 "
WRITE(*,*)"2. For 7 "
WRITE(*,*)"3. For 8 - 12 "
WRITE(*,*)"*****************************************************" READ(*,*)
d_values
DO
IF (d_values >= 1 .AND. d_values <= 3)EXIT
WRITE(*,*)"You entered an invalid choice, choose again"
READ(*,*) d_values
END DO
WRITE(*,*)"*****************************************************"
WRITE(*,*)"How much do you wish to bet??"
READ(*,*) amount
WRITE(*,*)"*****************************************************"
END SUBROUTINE
pf3
pf4

Partial preview of the text

Download Lab 9 Questions - Fortran Programming | CSCI 260 and more Lab Reports Computer Science in PDF only on Docsity!

Due : 11:59 PM., Wednesday, March 25, 2008 Objective : Familiarize yourself with FORTRAN SUBROUTINES and FUNCTIONS.

  1. Login to isengard.
  2. Change your current working directory to your csci260a directory.
  3. Make a lab9 subdirectory and then change directory to your lab9 directory.
  4. Copy over the files from the /class/csci260a/Assignments/lab9 directory to your lab (current) subdirectory.
  5. Use cp to copy and rename the lesson1 shell to mylesson1.f. Editing mylesson1.f
  6. Your program should play the dice game called lucky-7. A player starts out with $ and places how much they wish to bet and on what value set rolled. The pay back for the bet is 1 to 1 for dice values of 2 – 6, 3 to 1 for dice values of 7 and 1 to 1 for dice values of 8 to 12. Build a Subroutine that interacts with the user; it should get which dice values they wish to bet on and how much they wish to bet. If the use ever goes less that $0 the game should end. The user also has the option to end the game at the end of each round. Here is some useful code that you may use in the program. REAL:: x :::::::::: CALL RANDOM_SEED DO CALL getBet(bet, ch) CALL RANDOM_NUMBER(x) d1 = INT(x * 6) + CALL RANDOM_NUMBER(x) d2 = INT(x * 6) + ::::::::::: SUBROUTINE getBet(amount, d_values) IMPLICIT NONE !Must explicitly declare all variables INTEGER, INTENT(OUT):: amount, d_values WRITE(,)"*****************************************************” WRITE(,)"What range of dice values do you wish to bet on?" WRITE(,)"1. For 1 - 6 " WRITE(,)"2. For 7 " WRITE(,)"3. For 8 - 12 " WRITE(,)"*****************************************************" READ(,) d_values DO IF (d_values >= 1 .AND. d_values <= 3)EXIT WRITE(,)"You entered an invalid choice, choose again" READ(,) d_values END DO WRITE(,)"*****************************************************" WRITE(,)"How much do you wish to bet??" READ(,) amount WRITE(,)"*****************************************************" END SUBROUTINE

Here is an example of the program running:


This is a betting game called Lucky - 7, you start with $ Dice are rolled and you can bet on different dice values 1 - 6 pays out 1: 7 pays out 3: 8 - 12 pays out 1:



What range of dice values do you wish to bet on?

  1. For 1 - 6
  2. For 7
  3. For 8 - 12

1


How much do you wish to bet?? 50



Dice 1 's value is 2 Dice 2 's value is 6


The total amount is 8


You Lose. $ 50 :( You have $ 50 to work with Would you like to continue the game?? (y/n) y


What range of dice values do you wish to bet on?

  1. For 1 - 6
  2. For 7
  3. For 8 - 12

2


How much do you wish to bet?? 50



Dice 1 's value is 1 Dice 2 's value is 1


The total amount is 2


You Lose. $ 50 :( You have $ 0 to work with Would you like to continue the game?? (y/n) y


What range of dice values do you wish to bet on?

  1. For 1 - 6

Cat your second program source code. (to provide a listing of your code) cat mylesson2.f Compile your program again. (to verify no compilation error) g95 mylesson2.f Run your program. Show the results for 0 to 5 cars lambda = 1.6 (run six times). a.out

  1. Press ctrl-d to stop the scripting process.
  2. Submit your script file for grading. CLsubmit csci260a lab9 lab9.script