i have code which has a menu..

this code is for a tic tac toe game and i cant prevent the program from crashing .

So.........
when the user enters a variable e.g 'q' the program crashes. the happens whilst playing the game and whilst selecting a menu option. is there any way to prevent this???

Any help would be greatly appreciated.....

Recommended Answers

All 6 Replies

may we see your code, or would that be cheating?

is there any way to prevent this???

Yes there is, probably.

the better question is, why it crashes? What is the real reason?

my apologies lads..... i havent been on in a while. but the problem is not just with my current projects.

But all projects i complete with user input. e.g
cout<<"please enter a menu option"<<endl;
cin>>menu_option;

if i declare this variable as an int... then any char makes the error lines run to infinity until system memory runs out...

Is there a variable type i could use to prevent this.. it may be real simple. thanks in advance

If your options are numbers (less than 10), why not make it a char variable? If you needed the int value you could just subtract '0' from it.

char a = '1';
int b = (int)(a-'0');

thats a great idea thanks for the quick response....

success!!!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.