Solving Quadratic Equations: Invalid Inputs

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
Luke1986
Messages
2
Reaction score
0

Homework Statement



IMPLICIT NONE
REAL :: A, B, C, DISCR, X1, X2, x1i, x2i
CHARACTER(3)::ANS,ANS1
! Reads the coefficients for the quadratic equation
33 WRITE(*,*)")"Please enter a *REAL*NUMBER* coefficient ( A )."
READ(*,*)A
WRITE(*,*)"Please enter a *REAL*NUMBER* coefficient ( B )."
READ(*,*)B
WRITE(*,*)"Please enter a *REAL NUMBER* coefficient ( C )."
READ(*,*)C
WRITE(*,*)"The coefficients for A,B,C are",A,B,C

Homework Equations



This is only a little part of the whole program. My question is when I input a invalid character, like a letter or symbol, I want to tell the user that it is a error. Since A,C,B are all real variables how do I ask If I can let the user reenter a new value. Maybe an If statement? But I think you cannot compare reals and character. I am new to fortran my prof keeps failing me its my 4th time taking this course. It is very hard for me to comprehend so much details. Can someone assist me please? thank you!

The Attempt at a Solution

 
Physics news on Phys.org
Hi Luke1986! http://img96.imageshack.us/img96/5725/red5e5etimes5e5e45e5e25.gif

To validate input, you can read it as characters or a string and check that it conforms to a real before treating it as such.

I'm sure almost any textbook would have this or something similar as an example.

Good luck!
 
Last edited by a moderator: