I'm having a hard time finding some help on Exercism with this FORTRAN task.
The link to the task's mentoring portal is at
https://exercism.org/mentoring/external_requests/a5e5ee1e-08d0-11ec-81c5-853579c25f94 if any can be bothered.
Alternatively, with respect to the code below I'm having difficulty with the following two tests:
! Test 18: silence
call assert_equal("Fine. Be that way!", hey(""), "silence")
! Test 19: prolonged silence
call assert_equal("Fine. Be that way!", hey(" "), "prolonged silence")
I can't figure out why the my is_silence doesn't work.
-- Bruce
module bob
implicit none
contains
function is_shouted(statement)
logical :: is_shouted
character (len=*), intent(in) :: statement
if (scan(statement,"ABCDEFGHIJKLMNOPQRSTUVWXYZ") .gt. 0) then
if (scan(statement,"abcdefgijklmnopqrstuvwxyz") .eq. 0) then
is_shouted = .TRUE.
return
end if
end if
is_shouted = .FALSE.
end function is_shouted
function is_question(statement)
logical :: is_question
character (len=*), intent(in) :: statement
character (len=len(statement)) :: temp
temp = trim(statement)
is_question = scan(temp, "?", .TRUE.) .eq. len(temp)
end function is_question
function is_silence(statement)
logical :: is_silence
character (len=*), intent(in) :: statement
is_silence = len(statement) .eq. 0
end function is_silence
function hey(statement)
character(100) :: hey
character(len=*), intent(in) :: statement
character(len(trim(statement))) :: trimmed_statement
trimmed_statement = trim(statement)
if (is_shouted(trimmed_statement)) then
if (is_question(trimmed_statement)) then
hey = "Calm down, I know what I'm doing!"
return
else
hey = "Whoa, chill out!"
return
end if
end if
if (is_question(trimmed_statement)) then
hey = "Sure."
return
end if
if (is_silence(trimmed_statement)) then
hey = "Fine. Be that way!"
return
end if
hey = "Whatever."
end function hey
end module bob