Working? Lets see, I have
two temperatures. The
temps.size()
is thus 2.
middle = 2 / 2 = 1
If we follow your formula, you will compute the average of elements 1+2 (==3) and 1-2 (==-1).
However, the vector has only elements 0 and 1; no -1, no 3.
If the vector has 4 elements, indices {0, 1, 2, 3}, then middle=4/2=2, and the two centermost elements have indices 1 and 2.
If the vector has 6 elements, indices {0, 1, 2, 3, 4, 5}, then middle=6/2=3, and the two centermost elements have indices 2 and 3.
Always middle-1 and middle.
How about the odd sizes?
size = 1; middle = 1/2 = 0; { 0 }
size = 3; middle = 3/2 = 1; { 0, 1, 2 }
size = 5; middle = 5/2 = 2; { 0, 1, 2, 3, 4 } |
Neat.
I run programs from terminal. The terminal is open before, during, and after the program. I have no need for nor knowledge about any "keep open" idiom. There is, however, a thread on the subject:
http://www.cplusplus.com/forum/beginner/1988/