-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber_of_countries.f90
35 lines (28 loc) · 1.17 KB
/
number_of_countries.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
subroutine print_countries(countries)
implicit none
integer, intent(in) :: countries
integer :: avg_difference
! Get the difference assuming an average of 10 countries visited
! it has to be done as a real (float) and then cast to integer for aesthetic purposes
avg_difference = int(((countries - 10.0) / 10.0) * 100.0)
print '("You have been to ", I0, " countries!!")', countries
print '("That is ", I0, "% different from the world average of 10 countries visited.")', avg_difference
end subroutine
program number_of_countries
implicit none
integer :: countries, error
do
print '(A)', 'How many countries have you been to?'
read(*,*,iostat=error) countries
if (error .eq. 0 .and. countries .gt. 0 .and. countries .le. 200) then
! error .eq. 0 means there is no error, and countries must be an integer greater than 0 and less than 200
exit
end if
print '("That''s not a valid amount of countries, it must be between 1 and 200. Try again!")'
end do
if (countries .eq. 1) then
print '("You haven''t been out of the country yet, maybe one day")'
else
call print_countries(countries)
end if
end program number_of_countries