Results 1 to 9 of 9

Thread: Problems when dividing

  1. #1
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default Problems when dividing

    For some reason, when dividing, it randomly doesn't work for me. I have done a fresh installation, so just want a couple of people to check they get the same result as I do.
    Running this:
    SCAR Code:
    program New;
    var
      a: Extended;
     
    begin
      a:= 10/4;
      {a:= 100/4;
      a:= a/10;}

      if(a=2.5)then Writeln('a is correct')
      else if(a=2)then Writeln('a has been rounded down')
      else if(a=3)then Writeln('a has been rounded down')
      else Writeln('a doesn''t round and is incorrect');
    end.
    When I run that, I get 'a has been rounded in the debug'. When I comment out the first 'a:=' line and uncomment the other 2 'a:=' lines, it gives me 'a is correct'. So I'm just wondering, is this a scar error or am I just get something very wrong, as last time I checked, 10/4 = 2.5, yet when a:= 10/4, a=2, which makes no sense to me.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  2. #2
    Join Date
    Oct 2006
    Location
    Ontario,Canada
    Posts
    1,718
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    edit: i take this back

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

    Default

    SCAR automatically rounds when you do div or '/', talk to Freddy1990 if you want it changed

    @Xcan: Lol? Yes it does...


    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
    Oct 2006
    Location
    Ontario,Canada
    Posts
    1,718
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    since when... im testing this out now.

    edit: i guess you learn something new everyday...

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

    Default

    It is just an else - if. Usually the else is written on the line above it, but it doesn't really matter.


    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!

  6. #6
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    It doesn't seem to always auto-round(well, trunc) though, as the second method proves - 100/4 = 25 and 25/10 = 2.5, so it does work sometimes, though it seems only when you divide a variable. It's very peculiar - ahwell.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  7. #7
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    SCAR Code:
    program New;
    var
      a: Extended;

    begin
      a:= 10.0/4.0;
      {a:= 100/4;
      a:= a/10;}

      if(a=2.5)then Writeln('a is correct')
      else if(a=2)then Writeln('a has been rounded down')
      else if(a=3)then Writeln('a has been rounded down')
      else Writeln('a doesn''t round and is incorrect');
    end.

    Successfully compiled
    a is correct
    Successfully executed

    You need to add the . to make it an extended, otherwhise SCAR will round it down for you.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  8. #8
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I knew there was a simple solution. I just made a small function, but adding a . works much better
    Also got my prime 11 digit number checking as well, so it's a good day for me, yay
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

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

    Default

    Wow, Wizzup? for the win.


    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!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. SQL Problems. Please help!
    By Da 0wner in forum Web Development
    Replies: 10
    Last Post: 01-22-2009, 02:03 AM
  2. Computer problems... Terrible computer problems...
    By Jason2gs in forum News and General
    Replies: 22
    Last Post: 04-26-2007, 12:02 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
  •