position - check if input is within specified ranges in c++ -


i'm asking inputs , want have outputs depending on range within inputs fall.

example:

  • i accept inputs 0.3 0.55 etc.

  • range 0.0 1.

  • the "step" 0.1. meaning there 10 positions/checkpoints.

  • if input 0.3, since 3 times "step" should return "position 3", if smaller 0.3 larger 0.2 should return "between positions 2 , 3" etc.

question:

  • can done without explicit if-statements, or switch cases, possible positions??

it's easy write such function, based on value of (input-range_min)/(range_max-range_min)*10.

struct position {     int positionlow;     bool inbetween; };  position whereinrange(float input, float minscale, float maxscale, int numpositions) {     position res;     float fplace = (input-minscale)/(maxscale-minscale)*numpositions;     res.positionlow = int(floor(fplace));     res.inbetween = res.positionlow != fplace; 

}


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -