## Pascal

Moderators: None (Apply to moderate this forum)
Number of posts: 14016

This Forum Only

im getting an error when using program.. compiles fine! Posted by bobhaha on 23 Sept 2009 at 6:07 AM
ok i made a program which works out 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?

Re: im getting an error when using program.. compiles fine! Posted by anthrax11 on 23 Sept 2009 at 7:05 AM
With such equations you need to make some checks first. Check that a isn't 0, because you can't divide by 0. Also check that b*b-4ac isn't negative, because you can't root a negative number. If the conditions aren't met, then there are no solutions and the program should handle that.

Usually the best thing to do in these situations is to debug the program.

And the quadratic formula should be:
x:=(-b+sqrt((b*b)-(4*a*c)))/2*a;
x:=-b+sqrt(((b*b)-(4*a*c))/2*a);
Re: im getting an error when using program.. compiles fine! Posted by ducnthb on 5 Feb 2010 at 9:51 AM
the equation is incorrect, that is:
var x1,x2,a,b,c:real;
if b*b-4*a*c>0 then
begin
x1:=(-b-sqrt(b*b-4*a*c))/(2*a);
x2:=(-b+sqrt(b*b-4*a*c))/(2*a);
end;
Re: im getting an error when using program.. compiles fine! Posted by costas100 on 26 Mar 2010 at 5:05 AM
Make sure that you haven't forget the ' ; ' at the privious sentense

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic