sqrt.f90

I suggest you either typed  this as it appears into the compiler, or as an easier way, just copy and paste it!

Note: I do not claim the program will 100% work, but I give it my best. If it doesn't, try tweaking it yourself, or email me about it, and I'll modify and post the improved version later. Good luck!

 

PROGRAM sqrt
IMPLICIT NONE
REAL :: a, b, c, d !definitions block
REAL :: disc, x1, x2
INTEGER:: ans 
PRINT*, "Welcome to ADCY Discriminant Calculation Program" !introductory block
PRINT*, "The equation of the discriminant is as below:-"
PRINT*, " 2"
PRINT*, "discriminant= b -4ac"
1 PRINT*
PRINT*, "Enter value for a" !initial value input
READ*, a
PRINT*, "And for b"
READ*, b
PRINT*, "Finally... for c"
READ*, c
PRINT*, "Thank you. Please wait..."
PRINT*

disc = b**2-4*a*c 
IF (a==0) THEN !to make sure no program crashes caused by division by zero
GOTO 5 !occur
ELSE
END IF

IF (Disc<0) THEN !to test the validity of inputed values
GOTO 4
ELSE IF (Disc==0.0) THEN
GOTO 3
ELSE IF (Disc>0) THEN
GOTO 7
END IF

!if disc is equal to zero
3 x1=-b/2*a 
PRINT*, "Results just came in..."
PRINT*, "The discriminant is", disc
PRINT*, "And the value you have just typed on will give you a result of ", x1
PRINT*, "it means that the quadratic equation as represented by ax**2+bx+c=0"
PRINT*, "will give a twin root; a pair of root in which the two roots are of"
PRINT*, "the same value."
PRINT*
PRINT*, "Do you wish to enter a different set of values?"
GOTO 6

!if disc is more than zero
7 PRINT*, "Results just came in..."
PRINT*, "The discriminant is", disc 
x1=(-b+(b**2-4*a*c)**0.5)/2*a
x2=(-b-(b**2-4*a*c)**0.5)/2*a
PRINT*, "and the roots are", x1, "and", x2
PRINT* 
PRINT*, "As you can see, the discriminant is a positive number, therefore the"
PRINT*, "equation (-b+-(b**2-4*a*c)**0.5)/2*a will yield two valid numbers."
PRINT*
PRINT*, "Do you wish to enter a different set of values?"
GOTO 6

!if disc is less than zero
4 PRINT*, "Results just came in..."
PRINT*, "This program does not allow you to input a value that will spew out"
PRINT*, "complex numbers. The values for a, b & c that you have just inputed"
PRINT*, "violates this rule."
PRINT*
PRINT*, "Please enter another set of values"
GOTO 6

!if the division of zero occurred 
5 PRINT*, "Results just came in..."
PRINT*
PRINT*, "You have just inputed an invalid value for a."
PRINT*, "The value you input are not calculatable."
PRINT*, "Please try another set of values, this time with DIFFERENT value for a"
GOTO 6

!confirmation block 
6 PRINT* 
PRINT*, "Please enter your choice"
PRINT*, "Please do not enter any characters"
PRINT*, "(1 for yes, 2 for no)"
READ*, ans 
IF (ans==1) THEN
GOTO 1
ELSE IF (ans==2) THEN
GOTO 2
ELSE IF (ans/=1 .or. ans/=2) THEN
GOTO 8
END IF

!error block aka nimwitted foll's block
8 PRINT*, "Wrong input my friend. Try again"
GOTO 6

!ending
2 PRINT* 
PRINT*, "Thank you for calculating with ADCY Discriminant Calculation Program"
PRINT*, "Have a nice day"

END PROGRAM sqrt