* * *

Author Topic: dont know whats failing  (Read 354 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: 2606
  • 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.1.0 r59015M FPC 3.3.1 r39660 x86_64-linux-qt Chakra, Qt 4.8.7/5.11.1, Plasma 5.13.4
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.14

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

Birger52

  • New member
  • *
  • Posts: 36
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...)


Bart

  • Hero Member
  • *****
  • Posts: 3089
    • 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

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus