Q:

Lookup tables in C++

I have to implement small multimage graphic control, which in essence is an array of 9 images, shown one by one. The final goal is to act as minislider. 
Now, this graphic control is going to receive various integer ranges: from 5 to 25 or from 0 to 7 or from -9 to 9. 
If I am going to use proportion - "rule of three" I am afraid is not technically suistainable because it can be a source of errors. My guess is to use some lookup tables, but has anyone an good advice for approach?
Thnx

A:

I'm not sure look up tables are required. You can get from your input value to an image index between 0 and 9 proportionally:
int ConvertToImageArrayIndex(int inputValue)
{
    int maxInputFromOtherModule = 25;
    int minInputFromOtherModule = 5;

    // +1 required so include both min and max input values in possible range.
    // + 0.5 required so that round to the nearest image instead of always rounding down.
    // 8.0 required to get to an output range of 9 possible indexes [0..8]

    int imageIndex = ( (float)((inputValue-minInputFromOtherModule) * 8.0) / (float)(maxInputFromOtherModule - minInputFromOtherModule + 1) ) + 0.5;

    return imageIndex;
}

