Recent

Author Topic: dont know whats failing  (Read 2442 times)

sorcar

  • Newbie
  • Posts: 1
dont know whats failing
« 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.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: dont know whats failing
« Reply #1 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
 :)
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: dont know whats failing
« Reply #2 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...)

Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: dont know whats failing
« Reply #3 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