0
votes
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.

Hello sorry for bothering you, I previusly made this code for java and now was traying to translate it to pascal, but i cant figured it out why it says i have a syntax error, ";" expected but "ELSE" found in line (30,5). Can you help me please?

2
You need to surround the code after your else with begin and end - nepb

2 Answers

0
votes

Line 30 is an ELSE statement. The IF just above that has two lines of code between the else and if. Any time you have more than one line between an if and else, you must have a begin/end block. http://docwiki.embarcadero.com/RADStudio/XE8/en/Declarations_and_Statements#If_Statements

Change your code to

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

I managed to fix the issue by puting a semicolon in:

UNTIL numero = 1;