continuous loop
Nov 26, 2016 at 9:03pm UTC
tell me where the error ?? It is necessary to cause the R-Y-G-Y-R, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
void Traffic_Light::processing()
{
do
{
switch (current_color)
{
case RED:
screen.displayMessage("Red light" );
Sleep(2000);
current_color = YELLOW;
previos_color = RED;
case YELLOW:
screen.displayMessage("Yellow light" );
Sleep(4000);
if ( previos_color== RED)
{
current_color = GREEN; cout << "HERE GREEN\n" ;
}
else
{
current_color = RED; cout << "here RED\n" ;
}
case GREEN:
screen.displayMessage("Green light" );
Sleep(3000);
current_color = YELLOW;
previos_color = GREEN;
break ;
}
if (previos_color == GREEN)
{
current_color = YELLOW;
cout << "next yellow\n" ;
}
} while (true );
}
Nov 26, 2016 at 9:19pm UTC
You never break the loop, just the switch case. Use another boolean variable to keep track of it, then break the loop outside of switch. Also, all switch cases need to end in break.
Nov 26, 2016 at 9:21pm UTC
What type of varibles are the colors ?
I think you should declare them as an enum type, you have not declared them.
Topic archived. No new replies allowed.