1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran 90

  1. Apr 6, 2012 #1
    1. The problem statement, all variables and given/known data

    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

    2. Relevant 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 statment? 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!

    3. The attempt at a solution
     
  2. jcsd
  3. Apr 6, 2012 #2

    NascentOxygen

    User Avatar

    Staff: Mentor

    Hi Luke1986! http://img96.imageshack.us/img96/5725/red5e5etimes5e5e45e5e25.gif [Broken]

    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: May 5, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran 90
  1. Fortran 90 Question (Replies: 1)

  2. FOrtran 90 stucked (Replies: 4)

Loading...