I am new to C ++ and very close to a solution, but I still need help. My loop is working correctly for the first time. After that, when I enter the car number, it seems to grab some input somewhere and just perform an invalid color on the second pass. Obviously, I'm missing something, but I'm at a loss. Any help would be appreciated.
This is just a small fragment of my program, but there is a problem:
while (count < 3) { cout << endl << "Enter car color: blue, red or green in lower case. "; getline(cin, carColor[count]); if (!(carColor[count] == "blue" || carColor[count] == "red" || carColor[count] == "green")) { cout << "That is an invalid color" << "The program will exit"; cin.clear(); cin.ignore(); return 0; } cout << endl << "Enter car number between 1 and 99: "; cin >> carNumber[count];
source share