Hi there,(adsbygoogle = window.adsbygoogle || []).push({});

I've tried all I could in order to complete a very simple and basic program that finds the roots of any quadratic binomial.

You have to enter the coefficients a, b and c and it would find the roots. I could do that, but a problem occurred if I typed a=0. Of course if a=0 the binomial is not quadratic (and not even a binomial), so I wanted to let it know to the user of the program. Here my problems started... I don't know how to insert in my program that if a=0 then a message would appear saying that it isn't a quadratic binomial.

Here it comes :

I'm almost sure that I cannot type endif and then type if... Program findroot

implicit none

Real(8) :: a,b,c,delta,z,y,g

Write(*,*)'Enter a, b and c'

Read(*,*)a,b,c

if (a=0) then

write(*,*)'This is not a quadratic binomial'

endif

delta=b**2-4*a*c

If (delta>=0) then

z=(-b+sqrt(delta))/(2*a)

y=(-b-sqrt(delta))/(2*a)

Write(*,*)'The roots are',z,y

Elseif (delta<0) then

write(*,*)'The binomial has no root in R but in C its roots are',-b,'+i',sqrt(-delta)/(2*a),'and',-b,'-i',sqrt(-delta)/(2*a)

endif

End program findroot

But I tried many other things like

and changing the order of the if statements... I always get errors and the program doesn't compile. if (a=0) then

write(*,*)'This is not a quadratic binomial'

delta=b**2-4*a*c

elseIf (delta>=0) then

z=(-b+sqrt(delta))/(2*a)

y=(-b-sqrt(delta))/(2*a)

Write(*,*)'The roots are',z,y

Elseif (delta<0) then

write(*,*)'The binomial has no root in R but in C its roots are',-b,'+i',sqrt(-delta)/(2*a),'and',-b,'-i',sqrt(-delta)/(2*a)

endif

Any help is appreciated.

Note: If I erase the if (a=0) statement the program works well. (it compiles and find roots unless I type a=0).

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Fortran 90 very basic question : else if statement

Loading...

Similar Threads for Fortran very basic | Date |
---|---|

If statement for Monte Carlo integration | Sunday at 7:46 AM |

C/++/# How to use C++ in studying calculus | Apr 3, 2018 |

Fortran How to buy Fortran Programming Software Commersial License | Jan 30, 2018 |

Fortran [Fortran] something very peculiar | Oct 21, 2014 |

Help with a very simple fortran program. | Jan 22, 2012 |

**Physics Forums - The Fusion of Science and Community**