Fortran: How to work out if 3 variables make a right angled triangle

Click For Summary

Discussion Overview

The discussion revolves around a programming problem in Fortran, specifically how to determine if three inputted variables can represent the sides of a right-angled triangle using the Pythagorean theorem. The focus is on debugging a syntax error in the provided code.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • The original code attempts to use the equation a^2 + b^2 = c^2 to check for a right-angled triangle but encounters a syntax error.
  • One participant suggests that the issue may be related to the use of "=" instead of "==".
  • Another participant confirms that changing "=" to "==" resolved the syntax error and explains the difference between the two operators in Fortran.
  • There is a mention that the "==" operator is relatively new in Fortran, possibly influenced by C-based languages.

Areas of Agreement / Disagreement

Participants generally agree on the syntax issue related to the use of "=" versus "==", but the discussion does not resolve the broader context of using the Pythagorean theorem in the code.

Contextual Notes

The discussion does not address potential limitations in the approach to determining if the values can form a right-angled triangle beyond the syntax error.

Who May Find This Useful

Readers interested in Fortran programming, debugging syntax errors, or understanding the use of operators in programming languages may find this discussion useful.

Daniel1992
Messages
21
Reaction score
0

Homework Statement



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.


Homework Equations


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

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 :)
 
Physics news on Phys.org
"=" versus "==" comes to mind. What was the syntax error message?
 
lewando said:
"=" versus "==" comes to mind. What was the syntax error message?

Changing "=" to "==" fixed it. Why is that?

By the way thanks for that :approve:
 
Daniel1992 said:
Changing "=" to "==" fixed it. Why is that?
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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K