i need help fixing this pascal program

Status
Not open for further replies.

shiftyape

Honorable
Feb 23, 2013
48
0
10,580
program whileloop;

var
x:integer;
answer:string;
num:integer;

begin

num:=12345;

writeln('type "12345" if you would like to see nubers squaring up to 4096');
readln(answer);

if answer = num then
begin
writeln('press enter to see the numbers');
readln;
end;

else begin
x:=0;
end;

x:=1;

while x < 4097 do
begin
writeln(x,' squared is now ',x*x);
x:=x+1;
end;

writeln;
readln;

end.


this is the error i keep getting: whileloop.pas(29,2) Fatal: Syntax error, ";" expected but "ELSE" found
and also: whileloop.pas(23,14) Error: Incompatible types: got "LongInt" expected "AnsiString"
 
Solution

ex_bubblehead

Distinguished
Moderator
So many things wrong here....

And, since this looks suspiciously like a homework assignment, I'm not going to simply hand you the solution.

Just for starters:

1. You're looking for equality between a string and an integer
2. You've used ';' in places you shouldn't
3. Your routine has no proper exit, or structure, for that matter. No matter what you choose it falls through and squares the numbers. You have code in there that is better moved into a procedure.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


oh, wow, ive incited the rage of some random guy. who cares. if you did not come to this post to help, why did you answer at all? by the way this is my first day of trying to learn pascal, so sorry if its not some majestic and amazing program. it tends to take a few days to learn the basics. and no, this is not a school assignment, im doing this on my own free time, and people like you who criticize dont really encourage me that much. im just saying this because this is not the first negative feedback ive received today. go and bug someone else
 

Ijack

Distinguished

You really are an ungrateful little *****, aren't you. You post a homework assignment and then are rude to the person who takes the trouble to help you.

Take a different course - computer programming is obviously not for you.
 
Solution

Hawkeye22

Distinguished
Moderator
You could probably google for answers, but if you are trying to learn on your own, I suggest you go out and purchase a beginners guide to programming pascal.

writeln expects a string, x*x is not a string, it's numeric. Googling "pascal if else statement" should yield your other answer. We can't give you all the help, or you won't learn from it. ;)
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


wow. i never thought a simple question could yield an angry person swearing at me over something it took someone 1 minute to type. this is the age of the internet i guess. i realize i was rough on the guy to first post, and his post did help me, so i must say im sorry to him. i am just frustrated at all the negative feedback i have received since asking questions about pascal online. i will try something else.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


i am very sorry, my friend. just struggling to get real answers in the land of the internet. i apologize. thank you for your feedback
 

BaldrGeek

Honorable
Mar 24, 2013
3
0
10,510
oh, wow, ive incited the rage of some random guy. who cares. if you did not come to this post to help, why did you answer at all?

He was trying to help, which is what I had come here to do. He gave you some useful advice, like "you are comparing numbers with strings".

You can only help people that want to be helped. And in your case, you don't want help, you just want an excuse to act like a jerk.
 

ex_bubblehead

Distinguished
Moderator

I'll take this under advisement. However, in the future it would behoove you to accept constructive criticism with a great deal more graciousness, especially when you're the one asking for the assistance, otherwise you'll find it a very rough road ahead.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


ok, you guys, i apolagized, can we just drop this
 
Status
Not open for further replies.