Pascal语法错误

时间:2015-09-06 17:16:06

标签: syntax-error pascal

PROGRAM FactorPrimo(input,output);
VAR
    numero : integer;
    factor : integer;
    resto : integer;
    primo : integer;
    multiplicidad : boolean;

BEGIN
    write('Ingrese numero: ');
    readln(numero);
    factor := 2;
    primo := 0;
    multiplicidad := false;
    IF numero > 1 THEN
    BEGIN
        REPEAT
        BEGIN
            resto := numero MOD factor;
            IF resto = 0 THEN
            BEGIN
                numero := numero DIV factor;
                primo := primo + 1;
                multiplicidad := true;
            END
            ELSE IF multiplicidad = true THEN
                IF primo > 1 THEN
                writeln(factor,'^',primo);
                multiplicidad := false;
                ELSE
                writeln(factor);
                multiplicidad := false;
            ELSE
            factor := factor + 1;
            primo := 0;
            END;
        UNTIL numero = 1
        writeln(factor);
    END
    ELSE 
        write('Debe ingresar un numero mayor a 1');
END.

你好抱歉打扰你,我为java编写了这个代码,现在正在努力将它翻译成pascal,但我无法弄清楚为什么它说我有语法错误,&#34 ;;& #34;预期,但" ELSE"在第(30,5)行中找到。 你能帮帮我吗?

2 个答案:

答案 0 :(得分:0)

第30行是ELSE语句。上面的IF在else和if之间有两行代码。只要在if和else之间有多行,就必须有一个开始/结束块。 http://docwiki.embarcadero.com/RADStudio/XE8/en/Declarations_and_Statements#If_Statements

将您的代码更改为

IF primo > 1 THEN BEGIN
  writeln(factor,'^',primo);
  multiplicidad := false;
END ELSE BEGIN
  writeln(factor);
  multiplicidad := false;
END;

答案 1 :(得分:0)

我设法通过添加分号来解决问题:

UNTIL numero = 1;