Answer

There are at least three approaches, one of which is good.

  1. Change the declaration of I so that it is a REAL number. Although this would work, it is a bad idea to use a REAL variable as the control variable in a DO loop. The problem has to do with roundoff error. Take a look at page 512 of the text if you're curious about what the problem is.

  2. Convert the value stored in ``I'' into a real value before passing it along to ``SROOT''. One way to do this is to declare a REAL variable ``Y'', assign the value of ``I'' to ``Y'', and then pass the ``Y'' as the first argument to ``SROOT''. Although this works, it is kind of complicated and there's a much easier way to get the job done.

  3. The best (and simplest) solution is to use the intrinsic function ``REAL'', which converts any number into a REAL number. (There's also an intrinsic function ``INT'', which converts any number into an INTEGER.) Put this change into ``sroot2.f'' and make sure that it works.

Return to lesson.



Hamlet Project
hamlet@cs.utah.edu