Results 1 to 9 of 9

Thread: Determine if a value is even/odd in SCAR

  1. #1
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default Determine if a value is even/odd in SCAR

    I looked all through the manual - no go I am wondering how to have SCAR determin if a integer value is even (2,4,6,8, etc) or odd (1,3,5,7, etc).

    If this is not in SCAR, it must be added!
    ~ Harry


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  2. #2
    Join Date
    Mar 2006
    Posts
    3,051
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    If x mod 2 = 0 then (Even) else (Odd)


  3. #3
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    Thank you Tarajunky


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  4. #4
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    This will do it for you:

    SCAR Code:
    Const
    t = 3;//Value

    Procedure Determain;
    Var
    Value : String;
    Begin
      If t mod 2 = 0 Then
       Begin
        Value := 'Even';
      end else
        Value := 'Odd';
    end;

  5. #5
    Join Date
    Dec 2007
    Location
    Wizzup?'s boat
    Posts
    1,013
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    hmm.. im gonna save that
    it could come in handy down the track
    Project: Welcome To Rainbow

  6. #6
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Yeah might do but its still pretty easy.

  7. #7
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    if someone were to add such a simple function then i think it would be of more use if you made it complicated or else you're better off using mod

    something like this
    SCAR Code:
    // 'and' returns true if all are even, 'or' returns false if at least one is
    function EvenOdd(Numbers: TIntegerArray; Usage:string):boolean;
    var i: integer;
    begin
      for i := 0 to high(Numbers) do
      begin
        if Usage = 'and' then
        begin
          if (Numbers[i] mod 2) <> 0 then
          begin
            break;
            result := false
          end else
            if i = high(Numbers) then
              result := true;
        end else
          if (numbers[i] mod 2) = 0 then
          begin
            result := true;
            break;
          end;
      end;
    end;

    //returns all reesults of evenness
    function EvenOddArray(Numbers: TIntegerArray): array of boolean;
    var i: integer;
    begin
      SetArrayLength(result, GetArrayLength(Numbers));
      for i := 0 to high(Numbers) do
      begin
        if (Numbers[i] mod 2) = 0 then
          result[i] := true
        else
          result[i] := false;
      end;
    end;
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  8. #8
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    lol...

    SCAR Code:
    function IsEven(x: Integer): Boolean;
     begin
      Result := (x mod 2 = 0);
     end;

  9. #9
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by SKy Scripter View Post
    lol...

    SCAR Code:
    function IsEven(x: Integer): Boolean;
     begin
      Result := (x mod 2 = 0);
     end;
    HaHa that made me laugh!!!

    SKy you truly are funny!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Determine if a monster is dead.
    By Floor66 in forum OSR Help
    Replies: 1
    Last Post: 10-17-2008, 10:04 PM
  2. [Scar IDE] How to set jEDIT to edit scar files corectly!
    By LordGregGreg in forum Outdated Tutorials
    Replies: 16
    Last Post: 06-23-2007, 01:19 AM
  3. SCAR Divi 3.01 DONT associate .scar files!!!
    By chimpy in forum News and General
    Replies: 1
    Last Post: 04-21-2007, 08:49 PM
  4. Replies: 28
    Last Post: 06-22-2006, 04:27 PM

Posting Permissions

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