Array
It is not possible to store multiple values in a scalar variable as you wish. It is possible to store in a multi valued variable. A vector is the most obvious type to do this. An array can be stored in a single variable, but can only store multiple values in it because it is composed of several variables.
And yes, each element of the vector is an individual variable. So there’s no chance at all to keep it all in one, except with some trick possible if you have some restrictions.
If you choose a vector just add the order number whenever it meets the condition and then navigate the vector in a later loop.
Boolean
In fact you can make an array with an element for each city, there only keeps if the city meets the filter or not. In other words, it is a boolean operation.
Then you can use a trick and even use a variable. If you guarantee you will have a maximum of 8 cities you can create a variable of type char
(with a unsigned int
is possible up to 32 cities, in most architectures). There you guard if the city meets the criteria with only one bit.
Then the bit position is the index position of what would be its vector and the bit there indicates whether that city has above average temperature or not.
Of course, this only works if the cities have the order number in sequence, preferably from 0 to 7, but you can do it even starting from a larger number. It would also be possible if you could normalize to a sequence through mathematics.
You’d have to use the operator of bit to generate bits in the right places.
String
You still have the option to make a string with all values separated by some character or with fixed size. Technically it is still only a value, but you will give a semantics for this value that will behave as if there were several. I think I’ve gone too far and especially in this case I don’t see the need.