how to keep characters from breaking program

Hi
as you can tell from this I am new to programming. This is an excerpt from a calculator I am trying to make. This is so that the program doesn't break when you enter something other than 1 through 4, but it breaks if I input a letter. What can I do to the program so entering a letter won't hurt it? Sorry about the long-winded explanation.



int answer;

	cout<<"Would you like to multiply(1), divide(2), add(3), or  subtract(4)?"<<endl;
	cin>>answer;
		
	while (answer!=1-4)
	{
	cout<<"Sorry, I didn't quite get that, could you please repeat that?"                             <<endl;
		cin>>answer;
		
		if (answer!=1-4)
		{
			continue;
		}
		else if (answer==1-4)
		{
			break;
		}
		else if (answer==  Here Is The Problem  )
		{
			continue;
		}
	}

Last edited on
Probably a bit higher than your current level, but try reading this: http://www.cplusplus.com/forum/articles/6046/
Btw, if(answer == 1-4) doesn't do what you think it should. Instead it checks to see if answer is equal to -3.
check the used of isdigit.
Thanks for the help everyone
Topic archived. No new replies allowed.