Question: Hi I am wondering how should I make my input only get into the first if statement only if a alpha character is put in and nothing else, but if it is a integer I want it to go to the else statement that says "Please type a alphabet character". I tried cin.good() and stuff for the first if statement but it does not help either.
void makeamove(int map[][MAX])
{
char ch;
printmoves();
cout << "Please enter a move: ";
cin >> ch;
if(cin)
{
if(ch == 'w' || ch == 'W')
{
int i = findrowlocation(map);
int j = findcollocation(map);
i = i - 1;
if(i < 0)
{
cout << "Out of bounds!" << endl;
}
else
{
i = i + 1;
map[i][j] = 0;
}
i = i - 1;
map[i][j] = 1;
printmap(map);
}
else if(ch == 'd' || ch == 'D')
{
int i = findrowlocation(map);
int j = findcollocation(map);
j = j + 1;
if(j > MAX)
{
cout << "Out of bounds!" << endl;
}
else
{
j = j - 1;
map[i][j] = 0;
}
j = j + 1;
map[i][j] = 1;
printmap(map);
}
else if(ch == 'a' || ch == 'A')
{
int i = findrowlocation(map);
int j = findcollocation(map);
j = j - 1;
if(j < 0)
{
cout << "Out of bounds!" << endl;
}
else
{
j = j + 1;
map[i][j] = 0;
}
j = j - 1;
map[i][j] = 1;
printmap(map);
}
else if(ch == 's' || ch == 'S')
{
int i = findrowlocation(map);
int j = findcollocation(map);
i = i + 1;
if(i > MAX)
{
cout << "Out of bounds!" << endl;
}
else
{
i = i - 1;
map[i][j] = 0;
}
i = i + 1;
map[i][j] = 1;
printmap(map);
}
else
{
printmoves();
}
}
else
{
cout << "Please type a alphabet character" << endl;
}
}