Snippets

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

Updated by Hans Rogério Zimermann

File abastecimento01.f90 Modified

  • Ignore whitespace
  • Hide word diff
 endif
 
 if ( tipogas .eq. 'Premium') then
-    preco_litro = 3.49
+    preco_litro = 4.09
 endif
 
 if ( tipogas .eq. 'Diesel') then
Updated by Hans Rogério Zimermann

File abastecimento01.f90 Modified

  • Ignore whitespace
  • Hide word diff
    combustivel = "Diesel"
    call abastecer(tanque, valor, combustivel)
    
-    write(*,103)"Litros abastecidos ", tanque
-    write(*,*)"Tipo de combustivel  ", 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)
+101 format(' Total a pagar:  R$ ',f7.2)
 103 format(a20, f7.2)
    
 end program abastecimento
Updated by Hans Rogério Zimermann

File abastecimento01.f90 Modified

  • Ignore whitespace
  • Hide word diff
    combustivel = "Diesel"
    call abastecer(tanque, valor, combustivel)
    
-    write(*,103)" Litros abastecidos",tanque
-    write(*,103)" Tipo de combustivel",combustivel
+    write(*,103)"Litros abastecidos ", tanque
+    write(*,*)"Tipo de combustivel  ", 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( a25,f5.2)
+103 format(a20, f7.2)
    
 end program abastecimento
 
    preco_litro = 3.33
 endif
 
-end function
+end function
+
Created by Hans Rogério Zimermann

File abastecimento01.f90 Added

  • Ignore whitespace
  • Hide word diff
+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(*,103)" Tipo de combustivel",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( a25,f5.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 = 3.49
+endif
+
+if ( tipogas .eq. 'Diesel') then
+   preco_litro = 3.33
+endif
+
+end function
HTTPS SSH

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