Results 1 to 10 of 10

Thread: Maths Function?

  1. #1
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default Maths Function?

    Is there a maths function in SCAR that equals True or False if a number is even or odd?

    Thanks,
    Rich
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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

    Default

    I couldnt find any, so i whipped this together

    PHP Code:
    program NumberOdd;
    var
      
    Num string;
      
    Input integer;
      
    procedure DeclareNumberVar;
    begin
      Input 
    := 15;//the number you want to check
    end;

    begin
      DeclareNumberVar
    ;
      
    Num := FloatToStr(Input/2);
      if(
    GetOthers(Num) = '.'then//this checks if its odd, because if its even the result will be a whole number
      
    begin
        Writeln
    (IntToStr(Input) + ' is an odd number');
      
    end else
      
    begin
        Writeln
    (IntToStr(Input) + ' is an even number');
      
    end;
    end
    You can edit to your liking.

    Hope its what you wanted,
    no credit needed
    Project: Welcome To Rainbow

  3. #3
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    mod.

    SCAR Code:
    const
      TheNumberYouWantToCheck = 4;

    begin
      WriteLn(BoolToStr(TheNumberYouWantToCheck mod 2 = 0));
    end.


    Modulus, I believe it's called.

    "Script" above returns true/false depending on TheNumberYouWantToCheck is a even or odd number.

  4. #4
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    EDIT: Never mind, I got it working. Thanks guys.

    Benjaa, your's wasn't working, but I changed it to this and it did:

    SCAR Code:
    program NumberOdd;
    var
      Num : Extended;
      Input : Integer;

    procedure DeclareNumberVar;
    begin
      Input := 1;//the number you want to check
    end;

    begin
      DeclareNumberVar;
      Num := (Input/2);
      if(TrimNumbers(FloatToStr(Num)) = '.') then//this checks if its odd, because if its even the result will be a whole number
      begin
        Writeln(IntToStr(Input) + ' is an odd number');
      end else
      begin
        Writeln(IntToStr(Input) + ' is an even number');
      end;
    end.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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

    Default

    Quote Originally Posted by R1ch4 View Post
    Benjaa, your's wasn't working,
    woah, thats weird

    i tested it a couple of times and it worked perfectly
    was it showing errors or giving the wrong result?
    Project: Welcome To Rainbow

  6. #6
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    No, it wasn't any errors...It was just that every number was claimed to be even.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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

    Default

    Oh yeah... I just tested again

    It does come up all even

    I must've copied the wrong script up... my bad, thanks for pointing that out
    Silly me


    EDIT:
    Should probably use GetOthers, instead of TrimNumbers as well
    Project: Welcome To Rainbow

  8. #8
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    *feels totally ignored*


    My point was that to check if a number is even or not, just mod it by 2.



    Edit: Benjaa, I wasn't looking for creds. xD
    Edit2: You people know that I was just joking, right ..?

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

    Default

    Shh EvilChicken!

    You're making my scripting look less important :P

    Lol, i tried yours and it worked beautifully, well done. Here's some candy.
    I looked up an ubern00b tutorial for it for myself, but i couldnt find one.

    Ill stick to my non-simplified coding for now

    But i love your work EvilChicken

    Edit: Yes Of course i know you were joking evilchicken your a legend
    Project: Welcome To Rainbow

  10. #10
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    EC, you weren't ignored. Trust meh
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Maths Tools
    By A G E N T in forum Research & Development Lounge
    Replies: 1
    Last Post: 02-28-2008, 02:49 AM
  2. help plz with homework [maths]
    By RudeBoiAlex in forum News and General
    Replies: 5
    Last Post: 06-05-2007, 11:41 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
  •