1. Not finding help here? Sign up for a free 30min 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: How to work out if 3 variables make a right angled triangle

  1. Oct 23, 2012 #1
    1. The problem statement, all variables and given/known data

    I have a program which will sort out three inputted variables into order from lowest to highest. I now must get the program to work out if these 3 values could be the sides of a right angled triangle.


    2. Relevant equations
    I am going to use a^2+b^2=c^2 to solve this.

    3. The attempt at a solution

    Here is the code I used to attempt to solve the problem but I get a syntax error when I try to compile the code.

    If (a**2+b**2=c**2) THEN
    PRINT*,"These values can make the sides of a right angled triangle"
    ELSE
    PRINT*,"These values can not make the sides of a right angled triangle"
    ENDIF

    Any help would be appreciated :)
     
  2. jcsd
  3. Oct 23, 2012 #2

    lewando

    User Avatar
    Gold Member

    "=" versus "==" comes to mind. What was the syntax error message?
     
  4. Oct 24, 2012 #3
    Changing "=" to "==" fixed it. Why is that?

    By the way thanks for that :approve:
     
  5. Oct 24, 2012 #4

    Mark44

    Staff: Mentor

    Because = and == (or .eq.) are different operators.

    = is used only in assignment statements.

    == (or .eq.) compare two expressions for equality and is often used in IF blocks.

    BTW, it seems to me that the Fortran designers took == from the C-based languages. This operator is relatively new in Fortran.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran: How to work out if 3 variables make a right angled triangle
Loading...