recursive subroutine menu() !'recursive' is needed if the subroutine or function will call itself either directly or implicit
integer :: choice
logical :: valid !A boolean to indicate if the input is valid (.TRUE. or .FALSE.)
print *, '--------------------'
print *, '-----Calculator-----'
print *, '--------------------'
print *, 'Addition 1'
print *, 'Subtraction 2'
print *, 'Multiplication 3'
print *, 'Division 4'
print *, 'High precision division 5'
print *, 'Power 6'
print *, 'Terminate 0'
valid = .FALSE. !Make shure the while loop runs atleast once
do while (.NOT.valid)
read *, choice
valid = .TRUE.
if (choice == 1) then
call addition()
else if (choice == 4) then
call division()
else if (choice == 5) then
call hp_division()
else if (choice == 6) then
call power()
else if (choice == 0) then
print *, 'Program finished'
else
print *, 'False input, please enter valid input: '
valid = .FALSE.
end if
end do
end subroutine menu |