As others already suggested you misunderstood how conditional expressions works in C++. That said, I suppose there ways to improve your code. I suppose there are two scenarios:
(1) You trust the semaphore (
the user input) to be either '
red' or '
yellow' or '
green'.
In such scenario, the code could be written simply
if (stopLightColor == "green")
{
cout << "Continue" << endl;
}
else {
cout << "Please stop" << endl;
}
(2) You allow the semaphore (
the user input) to be broken, at times.
In such a scenario you HAVE to handle the '
broken' eventuality.
if (stopLightColor == "green")
{
cout << "Continue" << endl;
}
else if ( stopLightColor == "yellow" || stopLightColor == "red")
{
cout << "Please stop" << endl;
}
else {
cout << "Warning: the semaphore is broken, please go on very carefully" << endl;
}