Snippets

FSC1004 - CBFísica - Fortran Abastecimento - Funcao e Subrotina

Created by Hans Rogério Zimermann last modified
program abastecimento
character(len=10) :: combustivel
   print*,''
   print *, "Posto de Combustivel!"
   write(*,100)
   valor = 100.00 ! R$ 100,00
   combustivel = "Diesel"
   call abastecer(tanque, valor, combustivel)
   
    write(*,103)"Litros abastecidos? ", tanque
    write(*,*)"Tipo de combustivel? [Comum/Premium/Diesel] ", combustivel
    write(*,100)
    write(*,101) valor 
    write(*,102)
    
100 format(1x,60('-'))
102 format(1x,60('_'),/)
101 format(' Total a pagar:  R$ ',f7.2)
103 format(a20, f7.2)
   
end program abastecimento

!========================================
subroutine abastecer(tanque, valor, tipo)
!========================================
character(len=10) :: tipo
    tanque = valor / preco_litro(tipo)
end subroutine

!============================
function preco_litro(tipogas)
!============================
character(len=10) :: tipogas

if ( tipogas .eq. 'Comum')  then
    preco_litro = 3.9
endif

if ( tipogas .eq. 'Premium') then
    preco_litro = 4.09
endif

if ( tipogas .eq. 'Diesel') then
   preco_litro = 3.33
endif

end function

Comments (1)

  1. Hans Rogério Zimermann

    O que aconteceria com o código caso fosse adicionado o comando implicit none?

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.