I don't understand why it always returns FALSE even though every single variable satisfies conditions. I've tried to change the characters in the conditions to ascii numbers but it can not solve the problem. Any help, Thanks a lot.
I want to check every variable in an array if one of them is dissimilar to the characters in the alphabet or "SPACE" or ".", the function will return False.
bool KiemTraTenSinhVien(char ten[])
{
for (int i = 0; i < strlen(ten); i++)
{
if (ten[i] == (char)" " || ten[i] == (char)".")
{
}
else if (ten[i] >= (char)"a" && ten[i] <= (char)"z")
{
}
else if (ten[i] >= (char)"A" && ten[i] <= (char)"Z")
{
}
else
{
return false;
}
}
return true;
}
I also try this but the problem still be unsolved
bool KiemTraTenSinhVien(char ten[])
{
for (int i = 0; i < strlen(ten); i++)
{
if (ten[i] == ' ' || ten[i] == '.')
{
}
else if (ten[i] >= 'a' && ten[i] <= 'z')
{
}
else if (ten[i] >= 'A' && ten[i] <= 'Z')
{
}
else
{
return false;
}
}
return true;
}