0

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.....

5
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by Spiderpig085
0

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

0

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');
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.