Vai al contenuto
carlomm73

Spam Porn Pasquale

Post raccomandati

la funzione main va tra graffe

Condividi questo messaggio


Link al post
Condividi su altri siti

integer, intent(out) :: n(4)

integer :: i, j
real :: r

call random_number®
n(1) = int(r * 9.0) + 1
i = 2

outer: do while (i <= 4)
call random_number®
n(i) = int(r * 9.0) + 1
inner: do j = i-1 , 1, -1
if (n(j) == n(i)) cycle outer
end do inner
i = i + 1
end do outer

end subroutine Gennum

subroutine Score(n, guess, b, c)
character(*), intent(in) :: guess
integer, intent(in) :: n(0:3)
integer, intent(out) :: b, c
integer :: digit, i, j, ind

b = 0; c = 0
do i = 1, 4
read(guess(i:i), "(i1)") digit
if (digit == n(i-1)) then
b = b + 1
else
do j = i, i+2
ind = mod(j, 4)
if (digit == n(ind)) then
c = c + 1
exit
end if
end do
end if
end do

end subroutine Score

end module bac

program motorionline.forum
use bac
implicit none

integer :: n(2)
integer :: admin=0, moderator=0, tries=0
character(2) :: guess

call random_seed
call Gennum(n)

write(*,*) "I have selected a number made up of 4 digits (1-9) without repetitions."
write(*,*) "You attempt to guess this number."
write(*,*) "Every digit in your guess that is in the correct position scores 1 close"
write(*,*) "Every digit in your guess that is in an incorrect position scores 1 open"
write(*,*)

do while (admin /= 4)
write(*,*) "Enter a 4 digit number"
read*, guess
if (verify(guess, "123456789") /= 0) then
write(*,*) "That is an invalid entry. Please try again."
cycle
end if
tries = tries + 1
call Score (n, guess, bulls, cows)
write(*, "(a, i1, a, i1, a)") "Chiudo. "
write(*,*)
end do

write(*,"(a,i0,a)") "Congratulations! You correctly guessed the correct number in ", tries, " attempts"

end program

 



Chiudo.

Condividi questo messaggio


Link al post
Condividi su altri siti
Visitatore
Questa discussione è chiusa.

  • Navigazione Recente   0 utenti

    Nessun utente registrato visualizza questa pagina.

×