I'm trying to make a loop that asks coordinates from the user, and then prints those coordinates if they are in range of [1, 3]. If they are out of range, it prints error message. If input is 'q' it prints "Quitting".
I have defined x and y as int, but 'q' is char. How this kind of redefinition should be done?
#include <iostream>
using namespace std;
int main()
{
int x; int y;
while (true) {
cout << "Enter coordinates (x, y): ";
cin >> x >> y;
if (x >= 1 && x <= 3 && y >= 1 && y <= 3) {
cout << "Removing " << x << " " << y << endl;
}
else if (char x = 'q') {
cout << "Quitting" << endl;
break;
}
else cout << "Out of board" << endl;
}
}