0

This is a pascal program that returns factor . rate is the input which is given by the user. This program is throwing me error. please do have a look and help.

I want to rectify the error. I'm not able to find out the error since im very new to pascal and im trying to learn

program Mss; 
var
   rate,factor:integer;
begin
  readln(rate);
  case rate of
  1..2:begin
         factor:=(2*rate)-1;
         writeln(factor);
       end
  3:begin                             throws error here
      factor:=(3*rate)-1;
      writeln(factor);
    end
  4:begin
      factor:=(4*rate)-1;
      writeln:=(factor);
    end
  5:begin
      factor:=(3*rate)-1;
      writeln(factor);
    end
  6..8:begin
         factor:=rate-2;
         writeln(factor);
        end
   else begin        
          writeln(rate);
        end  
end;

This is a switch case which returns factor. rate is the input from user. this throws me an error.

Fatal: Syntax error, ";" expected but "ordinal const" found

1 Answers1

3

You have a few syntax errors. Your begin/end blocks need to be followed by ;.

writeln:=(factor) should be writeln(factor).

And you need an end. to finish the program.

program Mss; 
var
   rate,factor:integer;
begin
  readln(rate);
  case rate of
  1..2:begin
         factor:=(2*rate)-1;
         writeln(factor);
       end;
  3:begin               
      factor:=(3*rate)-1;
      writeln(factor);
    end;
  4:begin
      factor:=(4*rate)-1;
      writeln(factor);
    end;
  5:begin
      factor:=(3*rate)-1;
      writeln(factor);
    end;
  6..8:begin
         factor:=rate-2;
         writeln(factor);
        end;
   else begin        
          writeln(rate);
        end  
  end
end.

Also, please note that ; in Pascal is a separator, so you could write code like:

  6..8:begin
         factor:=rate-2;
         writeln(factor);
        end;

As:

  6..8:begin
         factor:=rate-2;
         writeln(factor)
        end;
Chris
  • 26,361
  • 5
  • 21
  • 42
  • 1
    You can say thank you on SO by marking any answer you feel has answered your question as "accepted." – Chris Oct 27 '22 at 21:58
  • 1
    Another minor style issue is that Pascal adheres to the standard PEMDAS operator precedence, that means here the parentheses in `(3*rate)‑1` are redundant. – Kai Burghardt Oct 28 '22 at 17:42