If getint value ends in a zero...

Discussion in 'AutoCAD' started by ffejgreb, Jun 21, 2004.

  1. ffejgreb

    ffejgreb Guest

    do this
    else do this

    Can this be doed? Check/compare the last digit of a stored integer that is?
    I'm not looking for the answer, just some hints.

    Jeff
     
    ffejgreb, Jun 21, 2004
    #1
  2. ffejgreb

    andywatson Guest

    Jeff,
    You could...
    1. convert the integer to a string (itoa)
    2. get the last character of that string (substr (1- (strlen <yourstring>)) <yourstring>)
    3. convert it back to an integer if you want (atoi)
    4. run it through a conditional statement...
    (cond
    ((= <lastdigit> 0) (dothis))
    ((= <lastdigit> 1) (dothis))
    ...
    )

    Andrew
     
    andywatson, Jun 21, 2004
    #2
  3. ffejgreb

    TCEBob Guest

    Yes.

    Hint: look at (rem value 10).

    rs
     
    TCEBob, Jun 21, 2004
    #3
  4. ffejgreb

    ffejgreb Guest

    Thank you Andrew. I will give this a try and see what happens.
     
    ffejgreb, Jun 21, 2004
    #4
  5. ffejgreb

    ffejgreb Guest

    Thanks TCEBob. My studying begins in earnest.
     
    ffejgreb, Jun 21, 2004
    #5
  6. ffejgreb

    ffejgreb Guest

    Damn. I failed abstracts in school. Maybe I'm smarter now. Probably not,
    but I'll give it a shot.
     
    ffejgreb, Jun 22, 2004
    #6
  7. ffejgreb

    andywatson Guest

    Definitely the most effecient and pretty way...just requires more abstract thinking.
     
    andywatson, Jun 22, 2004
    #7
  8. ffejgreb

    ffejgreb Guest

    Okay. I've been studying this and I am confused. In the vlisp help an
    example shown says (rem 42 12) returns 6. 42 divided by 12 is 3.5. Since
    it is returning an integer, I would expect the returned value to be 4.
    Where is 6 coming from? Also when I replace [value] in your example to me
    with an integer I get a return of 0. As in (rem 340 10). I am obviously
    missing something. Please elaborate if you can. I would appreciate it.

    Jeff
     
    ffejgreb, Jun 22, 2004
    #8
  9. ffejgreb

    Jeff Mishler Guest

    12 * 3 =36
    42-36 = 6 REMainder

    HTH
    Jeff
     
    Jeff Mishler, Jun 22, 2004
    #9
  10. ffejgreb

    Jeff Mishler Guest

    I hate it when I send too soon.....

    Any way, divide a number by 10, if it has a remainder of 0 then the number
    MUST end in a 0, too.

    OK?
    Jeff
     
    Jeff Mishler, Jun 22, 2004
    #10
  11. ffejgreb

    ffejgreb Guest

    Well the help file sure was clear as mud. I read it to say that it divides
    the first by the second and return the remainder, then divides that by the
    third and so on. As I said earlier, I failed abstracts. Thanks for the
    help Jeff. Now I understand where is was being pointed.

    Jeff also
     
    ffejgreb, Jun 22, 2004
    #11
  12. ffejgreb

    andywatson Guest

    Yeah,
    TCEBob cracked the door for you but didn't really let you in. The (rem) function doesn't give you the dividend, it gives you the remainder.
    (rem 10 3) returns 1. Ten divided by three equal three, remainder of 1.
    (rem 10 2) returns 0, since there is no remainder.
    (rem 3 5) returns 3, since five goes into three, zero times with a remainder of 3.
    That last example should set off some alarms for you. Another hint is that the number you'd like to analyze will always be the first argument.
    (rem <yournumberhere> ?)
    Your mission is to find the perfect number that you can always use as the second argument that will always give you a remainder that is equal to the last digit of your number.
     
    andywatson, Jun 22, 2004
    #12
  13. ffejgreb

    ffejgreb Guest

    There's a first. Me being accused of deep thought. Thanks! Like I said to Jeff Mishler, I just interpreted what I read wrong (man is my kid in trouble when he gets older).

    Thanks to all,

    Jeff
     
    ffejgreb, Jun 22, 2004
    #13
  14. ffejgreb

    TCEBob Guest

    As Marshal Dillon used to say about lisp, "It makes a man watchful -- and a
    little lonely."

    rs
     
    TCEBob, Jun 23, 2004
    #14
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.