Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic if statement/do loop query!

Status
Not open for further replies.

jumpunderaboat

Programmer
Mar 6, 2008
2
GB
I've made a program which outputs certain numerical data, angles in radians. However sometimes, my output has values like 7 and 8, which should really be 0.72 and 1.72(or -1.42).

So I'm guessing I need an if statement along the lines of:

if a>pi
then a=a-pi
else print *, a
end if

...But this doesn't seem to work. I was thinking I may need some kind of do loop here also but am a bit unsure how to implement it.

P.S. forgive me, I haven't used FORTRAN a great deal in the past!
 
Depends on what range of values is legal. Say you have lo and hi as the range.
Code:
do while (a .lt. lo)
   a = a + pi
end do
do while (a .gt. hi)
   a = a - pi
end do
print *, a
 
thanks, thats awesome - i didnt think of using a do while statement. one problem though, if have a value like -3.5 this becomes -0.35 or so. when it really ought to be around +2.8.

Imagine a circle around a point and I'm taking the lower vertical radius to equal 0. Therefore giving the horizontals values of +/- pi/2 and the upper vertical angle =pi=-pi

thanks for any help you can give me!
 
Not very clear from what you're saying. Should your range be -pi to pi or -pi/2 to pi/2

If you get -3.5, and the range is -pi..pi, then the result should be -3.5+pi = -0.35. Which is correct.

If you're expecting 2.8 then your range is 0..pi.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top