Input checking

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;
}
}
you are possibly looking for a structure like this
1
2
3
4
5
6
7
8
9
10
11
12
if (true)
{
	// do stuff
}
else if (true)
{
	// do stuff
}
else
{
	// do other stuff
}


please format your code with the format button <> if you want people to read it. (button is on the right of text entry box)
Topic archived. No new replies allowed.