PROGRAM prog1A
!Initialise the program and give it a name

	IMPLICIT NONE
	!Assume nothing about the variables used in this program
	REAL :: r, p, pi, s, apd
	!Declare real variables for the radius, population, pi, surface area and average population density
	
	pi = 4.0*ATAN(1.0)
	!Calculate the value of pi using the implicit function for arctan and put it into the variable pi
	
	PRINT*, 'What is the radius of the planet in metres?'
	!Prompt the user to input the radius of the planet
	READ*, r
	!Read the value into the variable r
	
	PRINT*, 'What is the population of the planet?'
	!Prompt the user to input the population of the planet
	READ*, p
	!Read the value into the variable p
	
	IF (r > 0) THEN
	!Check that the radius is positive
		s = 4*pi*r**2
		!Calculate the surface area of the planet
		PRINT '(a35, e11.5, a9)', 'The surface area of the planet is: ', s, ' metres^2'
		!Print the surface area for user reference
	
		apd = p/s
		!Calculate the average surface population density
		PRINT '(a35, e11.5, a19)', 'The average population density is: ', apd, ' people per metre^2'
		!Print the average population density
	ELSE IF (ABS(r) < TINY(r)) THEN
	!Check for the case where r = 0
		PRINT*, 'Invalid input: radius is zero with current precision.'
		!Print an appropriate error message
	ELSE
		PRINT*, 'Invalid input: negative radius.'
		!In the case that r < 0 print an appropriate error message
	END IF
	!End the if statement

END PROGRAM prog1A
!End the program
