Welcome to Laser Pointer Forums - discuss green laser pointers, blue laser pointers, and all types of lasers

LPF Donation via Stripe | LPF Donation - Other Methods

Links below open in new window

ArcticMyst Security by Avery

Any one know how to program in Turbo Pascal 7?

Joined
May 31, 2009
Messages
3,239
Points
63
ok ok I know what your going to say.. thats so 80's man! but I enjoy using pascal LOL :D

any way here is my problem

ok i made a program which works out the value of x from a quadratic formula when you enter values for a, b and c (which are "real" numbers) it puts the numbers in an equation but it does not work! it compiles fine.. but when i try using the program it says ERROR 207: invalid floating point operation

This is the line of code that it points too

x:=-b+sqrt(((b*b)-(4*a*c))/2*a);

I think its got something to do with all the operations happening in one line.. do you think this is a problem? also is there supposed to be any statement under "uses" (eg uses crt) so I can use the sqrt operation or multiple operations?

Thanks in advance.. i also have posted this in a programming forum.. but no replies at all!!

PS: +rep to who ever works it out.. i can also put the whole source code up if you need it.. its not that long!

-Adrian
 





Joined
Dec 26, 2007
Messages
6,129
Points
0
x:=-b+sqrt(((b*b)-(4*a*c))/2*a);

It could be that the 4 should be "4". I don't remember how to code in TURBO Pascal but that could be it.
Although I'm pretty sure there's an error in the variable setting, I mean, maybe you're trying to operate with different types of variables and that just won't work. Also, check if the sqrt argument is having negative values (sqrt(-2) will always, ALWAYS be there just to annoy everybody :p). Check that and let me know :)
 
Last edited:
Joined
May 31, 2009
Messages
3,239
Points
63
ok i tried a few things.. i tried changing a,b and c to an integer.. didnt work

i tried putting it as '4' but that gave me a Type Miss Match ERROR.. any other thoughts?

oh yeah and you cant get a - in the root.. cause the -4ac cancels the negative!

EDIT:

i just tried putting x as real and a, b and c as integer.. still nothing!
 
Last edited:
Joined
Dec 26, 2007
Messages
6,129
Points
0
oh yeah and you cant get a - in the root.. cause the -4ac cancels the negative!


Having read this I can say it could be the problem.
If the 4*a*c > b*b then you'll be getting a negative argument in the sqrt.

If you try replacing a;b;c with integer numbers, will the operation continue? Try that.

EDIT: Also, there's a formula error there, you're including the 2*a inside the sqrt and it should be outside of it.
 
Last edited:
Joined
May 31, 2009
Messages
3,239
Points
63
oh yes thats right! ok thats an easy fix!

... ok i got it working.. sort of, but i have to change -4*a*c to -4*a*-c.. thats the only thing i can get it working.. all the working out is right.. except the /2a thing BUT now i cant use a readln; function before the program ends.. this is kinda stuffed!! ill try what you said and tell you how i go!
 
Joined
May 31, 2009
Messages
3,239
Points
63
ok i got it working.. but still same problem with the end!

i think the problem is that i was using small numbers like 1,2,3 and they were getting negative roots like you said,... ill try work one out and test the program.. stay tuned!

edit: ok wow this thing is way off!! do you want me to upload the source code?
 
Last edited:
Joined
May 31, 2009
Messages
3,239
Points
63
heres the source code.. lol don't laugh i did this for simplicity not elegance!

program Quadratics;
uses crt;
var x: real;
x2:real;
a:integer;
b:integer;
c:integer;
z:integer;

begin
clrscr;
Writeln('Hi, I am the Quadratic Calculator!');
writeln('Press enter to get started');
readln;
clrscr;
writeln('Input the values for the Quadratic equation!');
writeln;
Writeln('Please use this as a guide! ax^2 + bx + c');
writeln;
write('Please enter the value of a ');
read(a);
write('Please enter the value of b ');
read(b);
write('Please enter the value of c ');
read(c);

x:=(-b)+Sqrt((b*b)-(4*a*c));
x:=x/2*a;
x2:=(-b)-Sqrt(((b*b)-(4*a*c)));
x2:=x2/2*a;

clrscr;
writeln('WOW THAT WAS EASY!');
writeln;
write('x= ');
write(x:2:2);
write(' or ');
writeln(x2:2:2);
writeln;
writeln('Type any number and press enter to exit!');
readln(z);

end.

ok im going to bed its 12:42am on a skool night! might need some sleep... any one that comes up with a solution gets +rep!
 
Last edited:
Joined
Nov 10, 2008
Messages
4,186
Points
63
I could get this program written in pseudo and then translate it to pascal but I don't know pascal, lol.
 
Joined
Jul 27, 2009
Messages
6
Points
0
This works great for me. As nikokapo said, you were getting negative (or too small) numbers under the sqrt. At the end you have to write some number because 'z' is integer. Or what problem at the end do you mean?
Before you start to calculate, you should do something like

Code:
if Sqr(b) < (-4*a*c) then begin
  WriteLn('Hasnt got any real solution');
  ReadLn;
  Exit;
end;

Regards.
 
D

Deleted member 8382

Guest
I have no idea of turbo pascal, but doing this in Java would be way easier xD
 
Joined
May 31, 2009
Messages
3,239
Points
63
This works great for me. As nikokapo said, you were getting negative (or too small) numbers under the sqrt. At the end you have to write some number because 'z' is integer. Or what problem at the end do you mean?
Before you start to calculate, you should do something like

Code:
if Sqr(b) < (-4*a*c) then begin
  WriteLn('Hasnt got any real solution');
  ReadLn;
  Exit;
end;

Regards.

ohh yes i see that is a good idea.. but even with larger numbers they are way off... i dont know why..

also Z is an integer because i can not display the result with out having a readln there.. but it won't work unless i have an integer value being read.. dont ask my y.. its kinda wierd!

EDIT: 555 posts!!
 
Last edited:
Joined
Jul 27, 2009
Messages
6
Points
0
Interesting, with the 'z' i thought, that you could only write
Code:
Readln;

Sorry for stupid question, but have you tried entering negative "c" or "b"? I still think its because of sqrt from negative number. I tried it with many numbers and i worked. Try for example a=6; b=-15; c=6 and you should get roots 2 and 0.5.

Regards.
 
Joined
May 31, 2009
Messages
3,239
Points
63
nope as i said i got 72 and 18.. its wierd... also i have tied putting in -c and -b but it comes up with floating point error..
 
Joined
Jul 27, 2009
Messages
6
Points
0
Oh, sorry, i expected good implementation so i didnt check the computing part.
Where you have
Code:
x:=x/2*a;
and
Code:
x2:=x2/2*a;

you should have

Code:
x:=x/(2*a);
and
Code:
x2:=x2/(2*a);

Regards.
 
Last edited:




Top