Results 1 to 2 of 2

Thread: Help with simple program

  1. #1

    Help with simple program

    my English is poor but that's okay ...

    I'm doing a free introductory course to the Pascal

    I need to do a program that I type the time in seconds and it shows in days, hours, minutes and seconds but this happening the following error, some results appear negative

    this is the code


    Code:
    program tempo;
    uses crt;
    
    var
    
    aux, aux1, aux2, s,  m,  h, d : integer;
    t : longint;
    
    begin
    clrscr;
    writeln('******* Digite o tempo em segundos *******');
    readln(t);
    
    d := t div (86400);
    aux := t mod (86400);
    h := aux div (3600);
    aux1 := aux mod (3600);
    m := aux1 div 60;
    aux2 := aux1 mod 60;
    s := aux2;
    
    writeln('Dias ', d);
    writeln('Horas', h);
    writeln('Minutos ', m);
    writeln('Segundos ', s);
    readln;
    end.
    for example if I type 150000

    Dias = 1
    Horas = 0
    Minutos = -32
    Segundos = -16

    thanks
    Last edited by WILL; 20-07-2011 at 09:21 PM. Reason: Put your code into a code block to easier viewing.

  2. #2
    What compiler are you using? By quick test it seems you need to declare everything as longint, or type convert them when using with variable t.

    By quick test with Lazarus i can get that happen only if i do this:
    aux, aux1, aux2, s, m, h, d : smallint;

    So with your compiler, integer = smallint which doesn't understand values over 32767.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •