Lazarus

Free Pascal => Beginners => Topic started by: sorcar on September 08, 2018, 04:50:21 pm

Title: dont know whats failing
Post by: sorcar on September 08, 2018, 04:50:21 pm
Hello, 
I'm new to FPC and Lazarus.
I've been trying to make this work for a while but it just doesn't do anything, can someone please give me an idea of what I am doing wrong?

PROGRAM numerosprimos1 (input, output);
VAR
    numero, n, p, base1, potencia, modulo, m: integer;
BEGIN
    n:=2;
    p:=1;
    base1:=0;
 
    readln(numero);
    while n<numero do
    BEGIN
        m:=n;
        modulo:=numero MOD m;
        if modulo=0 then
        BEGIN
            base1:=m;
            potencia:=p;
            m:=m*m;
            p:=p+1;
        END
        else
        BEGIN
            if base1>0 then
            BEGIN
              if potencia>1 then
              BEGIN
                writeln(base1,'^',potencia);
                potencia:=1;
                base1:=0;
                numero:=numero-m;
              END     
              else
              BEGIN
                writeln(base1);
                base1:=0;
                numero:=numero-m;
              END
            END
            else
              n:=n+1;
        END
   END
END.
Title: Re: dont know whats failing
Post by: Blaazen on September 08, 2018, 05:09:56 pm
I tested your program and
- if I enter prime number, program ends correctly without any output
- if I enter non-prime number, program falls to endless loop, without any output
 :)
Title: Re: dont know whats failing
Post by: Birger52 on September 14, 2018, 10:18:45 pm
Misisng som ; after END, where there is not an else follwing...
(Actually think you should be getting compiler errors...)

Title: Re: dont know whats failing
Post by: Bart on September 15, 2018, 01:16:47 pm
No reply from TS, so probably his deadline for this homework assignment has passed.

Bart
TinyPortal © 2005-2018