Why is my while loop not ending? It is giving the correct result, but it runs in an infinite loop. Is it due to operator precedence?
void equate()
{
int i = 0, n = 0;
while (((a[i] != '\0') && (b[i] != '\0')) || (n != 1))
{
if (a[i] > b[i])
{
std::cout << "\n" << a << " string is greater";
n = 1;
}
else if (a[i] < b[i])
{
std::cout << "\n" << b << " string is greater";
n = 1;
}
else
i++;
}
if (n == 0)
{
std::cout << "\n" << "Both strings " << a << " and " << b << " are equal";
}