Anyone know how to program?!?

LucJoe

Golden Member
Jan 19, 2001
1,295
1
0
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.
 

CarpeDeo

Golden Member
Feb 10, 2000
1,778
0
0
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
 

LucJoe

Golden Member
Jan 19, 2001
1,295
1
0
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
 

JetBlack69

Diamond Member
Sep 16, 2001
4,580
1
0
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.
 

LucJoe

Golden Member
Jan 19, 2001
1,295
1
0
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.
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
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++
 

POKOT

Member
Jul 10, 2001
51
0
0
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.
 

JetBlack69

Diamond Member
Sep 16, 2001
4,580
1
0
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.
 

LucJoe

Golden Member
Jan 19, 2001
1,295
1
0
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!