• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Anyone know how to program?!?

LucJoe

Golden Member
So, I'm trying to write a SIMPLE program in pascal to solve a quadratic equation. I am not into computer programming at all and i have to do this for a chem lab. If anyone can help me out it would be appreciated. Here's the program: it keeps telling me there's a problem in line 15! but i can't figure out why it won't compile:


program assignment2;

var a,b,c,x,z:real;

begin
x:=0.0;
z:=0.0;
writeln('Enter values for a, b, and c');
writeln('a??');readln(a);
writeln('b??');readln(b);
writeln('c??');readln(c);
z:=sqrt((b*b-4*a*c)/(2a)); (***This is the line where the problem supposedly is (I think)***)
x:=(-b+z);
writeln('One of the solutions of the quadratic equation with those coefficients is ',x);
writeln('Continue?');readln;
x:=(-b-z);
writeln('The other solution is',x);
writeln('Press any key to exit the program...');readln;

end.
 
this is just a guess- but i'm pretty sure it's a parenthetical problem

z:=sqrt(b*b-4*a*c)/(2a); should be

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

sqrt(arg) only takes one argument
 
Tried that, and for some reason it still doesn't work...

I'm so confused.

I edited the original message to show how I have changed those parentheses.


Edit: Here's the error message the compiler gives me:

15 / 24 assign~1.pp Fatal: Syntax error, ) expected but identifier A found
 
Assuming the lines start at one, here is the 15th line
writeln('Continue?');readln;
I think the problem might be in the readln because in all the other instances, you have readln(SOMEVARIABLE); I assume you want to continue when the user enters Y or y and not continue for any other character. Try deleting that line and see if it compiles.
 
Yea, the line numbering is weird, but the problem is definitely in the line that i pointed out. The compiler highlights the line that has the problem.
 
did you try 2*a instead of 2a?

and the compiler doesn't always point out the right line, at least not in c and c++
 
program assignment2;
var a,b,c,x,z,y:real;
begin
writeln('Enter values for a, b, and c');
write('a=');readln(a);
write('b=');readln(b);
write('c=');readln(c);
y:=b*b-4*a*c;
if y<0.0 then begin writeln('No real roots, bye..');halt(0) end;
z:=sqrt(y);
x:=(-b+z)/(2*a);
writeln('One of the solutions of the quadratic equation with those coefficients is ',x);
writeln('Continue (ENTER)?');readln;
x:=(-b-z)/(2*a);
writeln('The other solution is',x);
write('Press ENTER to exit the program...');readln;
end.
 
Originally posted by: POKOT
program assignment2;
var a,b,c,x,z,y:real;
begin
writeln('Enter values for a, b, and c');
write('a=');readln(a);
write('b=');readln(b);
write('c=');readln(c);
y:=b*b-4*a*c;
if y<0.0 then begin writeln('No real roots, bye..');halt(0) end;
z:=sqrt(y);
x:=(-b+z)/(2*a);
writeln('One of the solutions of the quadratic equation with those coefficients is ',x);
writeln('Continue (ENTER)?');readln;
x:=(-b-z)/(2*a);
writeln('The other solution is',x);
write('Press ENTER to exit the program...');readln;
end.

looks good.
 
Originally posted by: gopunk
Originally posted by: LucJoe
That worked..

Programming is so picky!

so it was the 2*a?

Yea, that's what I was replying to.. I didn't see the other ones posted.

But wow! thanks a lot POKOT. One of the things I was trying to figure out how to account for was the negative number thing, but your's worked perfectly!
 
Back
Top