See here for SetRoom
and GetRoom
methods that do not use arrays.
Using GetRoom
and the individual int
member variables Room1
to Room4
you can find the room with the maximum number of bottles like this:
int maxValue = Room1;
int maxRoomNumber = 1;
for (int i = 2; i <= 4; i++) {
int value = GetRoom(i);
if (value > maxValue) {
maxValue = value;
maxRoomNumber = i;
}
}
Note: The Room1-4
variables must be declared as member variables. This means in the class, not in a method, for the GetRoom
method to work.
solved What is a long, simplified, standard, alternative to an Array or LINQ? [duplicate]