I wanted to use "if" in a program, but I don't know where is my mistake.
I wanted to solve this problem using fortran: x and y roll the dice a hundred times. Each dice that shows a larger number gets one point. If the number of two dice is equal, neither of them gets points. Write a program that randomly plays the game and determines which one gets the most points after 100 throws and wins
my codes :
CALL RANDOM_SEED
1 x=rand() print*,x if(x>0 .and. x<1./6)then print*,"x=1" elseif(x>1./6 .and. x<2./6)then print*,"x=2" elseif(x>2./6 .and. x<3./6)then print*,"x=3" elseif(x>3./6 .and. x<4./6)then print*,"x=4" elseif(x>4/6. .and. x<5./6)then print*,"x=5" elseif(x>5./6 .and. x<1)then print*,"x=6" endif y=rand() print*,y if(y>0 .and. y<1./6)then print*,"y=1" elseif(y>1./6 .and. y<2./6)then print*,"y=2" elseif(y>2./6 .and. y<3./6)then print*,"y=3" elseif(y>3./6 .and. y<4./6)then print*,"y=4" elseif(y>4/6. .and. y<5./6)then print*,"y=5" elseif(y>5./6 .and. y<1)then print*,"y=6" endif goto 12 nx=0 ny=0 n=0 12 if(x>y)then ! here is my problem nx=nx+1 elseif(y>x)then ny=ny+1 endif print*,"nx=",nx,"ny=",ny n=n+1 if(n<101)goto 1 pause stop end
the problem: if x=y I do not want to add the number 1 to nx or ny but:
Aucun commentaire:
Enregistrer un commentaire