-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.f90
39 lines (31 loc) · 969 Bytes
/
index.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
! Basically my first program is gonna be a guess the number game
program numberGuess
implicit none
real :: number
integer :: guess, tries
integer :: lowerBound, upperBound
character :: playAgain
logical :: correctGuess
lowerBound = 1
upperBound = 10
correctGuess = .false.
call random_number(number)
number = lowerBound + nint((upperBound - lowerBound + 1) * number)
tries = 0
do
tries = tries + 1
print *, "Enter your guess:"
read *, guess
if (guess == number) then
correctGuess = .true.
print *, "Hacks?!?! You guessed the number in", tries, "tries."
else if (guess < number) then
print *, "Too low! Try again."
else
print *, "Too high! Try again."
end if
print *, "Do you want to play again? (y/n)"
read *, playAgain
if (playAgain /= "y") exit
end do
end program numberGuess