• Trying

    From Sean Dennis@1:18/200 to All on Sat Jun 4 19:20:34 2005
    Hello, All.

    I'm trying to write a biorhythm door for a friend, but am stymied at one point Here's the code (rather sloppy right now):

    dClrScr;
    Write('Your birthyear [XXXX]: ');
    dReadI(BirthYear);
    Work := (2005-BirthYear)*365;
    DCrlf;
    dWriteLn('You are ' + itos(Work) +' days old.');
    dCrLf;
    Temp := Sin(2*(Work/23)*Pi)*100;
    dWriteLn('Your physical percentage is '+Temp+'%.');

    Temp is declared Real. I know I have to convert Temp into an integer value to write it out (well, longint) using the doorkit, but when I use Round or Trunc, I get either zero or a negative value.

    Work is the number of days you've been around (done by a rather loose formula of 2005-Birthyear*365.25).

    Unfortunately, math is not my strong spot and I know that there's a simple solution to this somewhere. Can anyone help?

    Later,
    Sean

    // hausmaus@darktech.org | http://outpostbbs.net | ICQ: 19965647

    --- GoldED+/W32 1.1.5-21011
    * Origin: Outpost BBS - outpostbbs.net (1:18/200)
  • From Roelof Beverdam@2:280/5218 to Sean Dennis on Sun Jun 5 09:50:35 2005
    Hello Sean,

    Temp := Sin(2*(Work/23)*Pi)*100;
    dWriteLn('Your physical percentage is '+Temp+'%.');
    [cut]
    Unfortunately, math is not my strong spot and I know that there's a simple solution to this somewhere. Can anyone help?

    What exactly is your problem? And what compiler + version are you using? And where exactly does the compiler complain with which error code?

    You did realize you should use a ftos(..) in the dWriteLn argument, did you? Or
    itos(..) after conversion to integer - like you did in previous lines.

    And as for Turbo Pascal: you should use the correct floating point format (real
    versus double) and enable it with the $N directive. And if you are not emulating floating point operations, be assured to run on 80386 or better - or the systems to have a math coprocessor.

    Cheers,
    Roelof Beverdam

    --- Dutchie V3.10.11
    * Origin: The Beaver's Nest (2:280/5218)
  • From Jake Ng to Sean Dennis on Sat Jul 2 13:53:10 2005
    Re: Trying
    By: Sean Dennis to All on Sat Jun 04 2005 07:20 pm

    Temp := Sin(2*(Work/23)*Pi)*100;
    dWriteLn('Your physical percentage is '+Temp+'%.');

    Temp is declared Real. I know I have to convert Temp into an integer value write it out (well, longint) using the doorkit, but when I use Round or Trun I get either zero or a negative value.

    you can convert a Real number to a printable string like so:
    Str( <#> : <width> : <decimals> , <string> );
    ex: Str(Temp : 3 : 1, TempStr);