numbers to the boxes

-1.28706
-1.20833
-0.500325
-0.432992
-0.0959883
-0.0111589
0.0202377
0.123189
0.123607
0.273401
0.437932
0.722443
0.912102
0.944231
1.19091
1.33872
1.35194
1.39203
1.41976
1.45984
1.67345
1.88901
1.9257
1.957 


These are some numbers and I have 20 boxes. (Numbers are provided by the user. So I have a " std::cin << " at the beginning of the code.)

I would like to do something like this:

1
2
3
4
5
6
7
8
9
if ( number > -2. && number < -1.8 )  box1 = true;
if ( number > = -1.8 && number < -1.6 ) box2 = true;
if ( number >= -1.6 && number < -1.4 ) box3 = true;
if ( number >= -0.4 && number < -0.2) ... 
.....
if ( number >= 0 && number < 0.2) ... 
.....
.....
if (number >= 1.8 && number < 2.0 ) box20 = true;


The range is between (-2.0 , 2.0) .

at the end of the code, I will print the boxes information whether it's true or not... What is the simplest way to do this ?

I have already a similar thread here but this was is long (and also advanced) for me. http://www.cplusplus.com/forum/general/49226/ . I believe, there should be a much simpler way to do this, instead of writing a class.

thanks in advance.
Last edited on
Topic archived. No new replies allowed.