color counter

I'm hoping someone might be able to help me out.

I'm trying to add a counter to count the number of times a color sensor detects a certain color. This is for a project I am doing that involves an autonomous robot being able to detect when it has entered and exited a room. The rooms are lined with colored tape. While in the room, it also has to detect a certain color, in my case red, and perform a function when it detects that color. Once that is completed, the robot needs to exit the room and continue on to 3 other rooms and do the same thing.

The room colors are red, green, yellow, and blue.

I am brand new to coding and this has me wanting to punt my laptop through the wall. Can anyone take a look at what I have and give me some direction? I have tried to return boolean values, inserted nested while loops, nested if statements, but ive had no luck. I have attached my .ino file HOPEFULLY.

My color value ranges are fairly precise so it distinguishes between room colors and target colors pretty well. The only problem I have is that the "blue room" value and "red room" values are really close but that's ok. As long as it knows its entered and then exited the room. A plus would be to determine that if it somehow ends up back at a room its already been in, it knows not to enter that room. Be gentle when critiquing my code, as I said, I'm about 10 weeks in to coding. THANKS!

pillbotalmostthere.ino (8.21 KB)

Please post your code in code tags

void yellowroomcounter()
  yellowroomread = 0;
  if (yellowroomread < 2)

After setting yelloroomread to 0, what are the chances that the value in yellowroomread will be less than 2?

What will the value of yellowroomread ALWAYS be when that function ends?