We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,078 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Error 207:Invalid floating point operation??? in Turbo PASCAL

program Q2 (Input,Output);

var

  X,Y,T1,T2 : Integer;
  Flag1,Flag2,Flag3 : Boolean;
  SquareRoot,CubeRoot,Z,D1,D2 : Real;

begin

  X := 1;

  Flag1 := True;
  Flag2 := False;
  Flag3 := False;

  while Flag1 do
    begin
      Y := X-1;
      SquareRoot := Sqrt(Y);
      T1 := Trunc(SquareRoot);
      D1 := SquareRoot - T1;

      if(D1>0) then
         Flag2 := False;
      
      Z := X+1;
      CubeRoot := Exp((1/3) * Ln(Z));
      T2 := Trunc(CubeRoot);
      D2 := CubeRoot - T2;

      if(D2>0) then
         Flag2 := False;
      
      if ((Flag2) and (Flag3)) then
        begin
         Flag1 := False;
         WriteLn;
         Write('Value = ',X,' ',D1,' ',D2);
        end
      else
         X := X + 1;
    end;

end.

I'm trying to find way to make cube root in Turbo PASCAL but when i use CubeRoot := Exp((1/3) * Ln(Z)); keeps giving me runtime errors this is the question for the homework

It is said that there is only one natural number n such that n-1 is a square and n+1 is a cube that is n-1 = square x and n+1 = cube y for natural numbers x and y. find n in PASCAL

2
Contributors
4
Replies
1 Day
Discussion Span
4 Years Ago
Last Updated
5
Views
Question
Answered
animefun2
Newbie Poster
17 posts since Jul 2008
Reputation Points: 3
Solved Threads: 0
Skill Endorsements: 0

Well the answer would be more evident if you debugged it.

You tell me what the values of each part of that line works out to be, so Z, ln(Z), etc.. you tell me which bit fails.. and what the values are.

Are you really using turbo pascal from the 80s? or do you mean the turbo delphi products?

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
Skill Endorsements: 1

Yes the compiler i used is Turbo Pascal unfortunately i checked if the CubeRoot & SquareRoot are computing correctly so i tested them turns out

Ex when input X = 4

The result:

SquareRoot := Sqrt(X);  { Turn out correct  2.0000000000E+00 }
T1 := Trunc(X); { also correct 2 }
D1 := SquareRoot - T1; { is correct 0.0000000000E+00 }






{but with the cube is a different story }
CubeRoot := Exp( V * Ln(Z) ); { Turn out correct 1.5874010520E+00 }
T2 := Trunc(X); { also correct }
D2 := CubeRoot - T2; { is not correct 5.8740105200E-00 it should come out
{ 0.58740105200E+00 }

I also try to use the same program with Dev Pascal its seem to have the same problem with D1 :( it would seem that i cant calculate both of them in the same place

animefun2
Newbie Poster
17 posts since Jul 2008
Reputation Points: 3
Solved Threads: 0
Skill Endorsements: 0

Forgive my denseness (its past 11, and Im about to go to bed but..)

5.8740105200E-00 = 0.58740105200E+00

as 5.8740105200E surely is 0.587... just as 0.587E+00 is also 0.587....

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
Skill Endorsements: 1

I discovered that u have to seperate the two operation of square root and cube root and it worked and i changed the compiler thanks for the help :twisted:

animefun2
Newbie Poster
17 posts since Jul 2008
Reputation Points: 3
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 4 Years Ago by LizR

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0660 seconds using 2.68MB