0
votes

I've got a problem with pascal. I'm learning it at school and because I already use Java, I'm a little bit confused. But that is not exactly why it doesn't work. I am trying to make a simple if (condition) write(this) else write(that) program, that runs in the cmd. When I try to compile the following code, it says, I have to write a ; instead of else, but that just seems odd.

program Project1;
var max : integer;
var max2 : integer;

begin
    writeln('Max: Oh no, I'm an integer');
    writeln('Which integer is max supposed to be?');
    readln (max);
    writeln('Max: I don't want to be a', max);
    writeln('Multiply Max');
    readln (max2);

    if (max = max * max2) then
        writeln('NO, I do not want to be a', max);
    else
        writeln('I think I could live with being a ', max * max2);

    readln;
end.   
2
Double the apostrophe, the doubling acts as escape: Writeln('I don''t want to be a ',max); - Marco van de Voort

2 Answers

3
votes
program Project1;
var max : integer;
var max2 : integer;
begin
writeln('Max: Oh no, Im an integer');
writeln('Which integer is max supposed to be?');
readln (max);
writeln('Max: I dont want to be a', max);
writeln('Multiply Max');
readln (max2);
if (max = max * max2) then
 writeln('NO, I do not want to be a', max)
 else
  writeln('I think I could live with being a ', max * max2);

readln;
end. 

Problem was with if statement, because if is just one line you don't need to close line with ";" and was problems with string lines, don't use " ' " in middle of string

2
votes

Try fixing your apostrophes in the writelns, and see if that helps:

Write apostrophe sign in writeln function - Pascal