%D. Dal Bello 7/19/2005
%circle2.m

clear all
	
%Introduce program to user
%\n is a line break

fprintf('\nThis program will calculate the area and circumference of a circle.\n\n')

radius=input('Enter the radius of the circle: ')  %input radius


%check if entered radius is positive and real

if radius > 0 & imag(radius)==0   % checks if imaginary part is zero
  %perform calculations
    area=pi*radius^2;    %calculate area
    circumf=2*pi*radius; %calculate circumference

  %formatted results... %8.3f: floating-point field 8 units wide, 
  %3 places after decimal point. A word has been placed after the
  %number to show the effect of the 8-unit wide space.

    fprintf('The circle''s area is A = %8.3f. That''s great.\n\n', area)
    fprintf('The circumference is C = %8.3f. Wow.\n', circumf)


%check if entered radius is non-positive & real, output error message

elseif radius <=0 & imag(radius)==0 
    fprintf('Radius must be positive. It cannot be %8.3f.\n', radius)

%check if entered radius is complex, output error

elseif imag(radius)~=0  % ~=0 means not equal to 0
    fprintf('Radius must be real. It cannot have an imaginary part, %8.3fi.\n\n', imag(radius))
          %Note character i must be included in the output
          %imag(radius) only gets the constant before i 

end  %end if
