You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This example is meant as a helpfull guide to see how Fortran looks in practice. And will show how to use subroutines, precision and simple arithmetic functions in fortran. 


Main
program main
implicit none
	call menu()
end program main


Menu
recursive subroutine menu()
	integer :: choice
	integer :: valid = 0
	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 = 0	
	do while (valid == 0)
		read *, choice
		valid = 1
		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, try again'
			valid = 0
		end if
	end do
end subroutine menu



Page content



  • No labels