This is supposed to check if an entered string is a valid license number. A valid number cannot have any lower case letters or spaces. If I enter "cat", it should see that the character "c" is lower so it should set bool isValid to false, break from the loop and then print "cat is not a valid license number." However it doesn't and it just makes the bool isValid to whatever I set it to in the beginning which was true. So if I initialized it to false and input "CAT" isValid would still be false.
int main()
{
// Input
cout << "Enter a valid license number: ";
string license_number;
getline(cin, license_number);
cout << endl;
// Initialize boolean
bool isValid = true;
// Loop to check for space or lowercase
for (int i = 0; i < license_number.size(); i++)
{
if (isspace(license_number[i]) || islower(license_number[i]))
{
bool isValid = false;
break;
}
else
bool isValid = true;
}
// Output
if (isValid == true)
cout << license_number << " is a valid license number." << endl;
else
cout << license_number << " is not a valid license number." << endl;
return 0;
}