Anyone see a better way of doing this

This is a discussion on Anyone see a better way of doing this within the C Programming forums, part of the General Programming Boards category; I have a list of possible exposure values, which I need to compare with the calculated value, and choose the ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    104

    Anyone see a better way of doing this

    I have a list of possible exposure values, which I need to compare with the calculated value, and choose the closest one.

    Code:
    // This finds closest match
    If 0<exposure<0.00025
    Then  Output "Closest exposure value is 1/4000"
    Else If 0.00025<exposure<0.0005
    Then Output "Closest exposure value is 1/2000"
    Else If 0.0005<exposure<0.001
    Then Output ""Closest exposure value is 1/1000"
    ...
    This is quite tedious as there are 20 values or so to compare with . Does someone see a better way of doing this ?

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    make an array of limit values and use the loop

    also note that
    If 0<exposure<0.00025
    is not a C
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Yep , it's just pseudocode I need to make for now

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,300
    Quote Originally Posted by ICool View Post
    Does someone see a better way of doing this ?
    You could use log to calculate the table starting point in O(1) time.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21