I have a program that prints a menu & the user is prompted to input a choice(1,2 or 3) if they input anything else, the output should be "Invalid Choice".
My Problem is that if a user inputs anything other than 1,2 or 3, then the program crashes, instead of doing what it should do "Invalid Choice".
What I am essentially trying to do is make the menu loop continuously unless option 3 is input (option 3 = quit).
Any advice would be really helpful. Such as should I uuse a whole new method of making the menu loop?
I have a program that prints a menu & the user is prompted to input a choice(1,2 or 3) if they input anything else, the output should be "Invalid Choice".
My Problem is that if a user inputs anything other than 1,2 or 3, then the program crashes, instead of doing what it should do "Invalid Choice".
What I am essentially trying to do is make the menu loop continuously unless option 3 is input (option 3 = quit).
Any advice would be really helpful. Such as should I uuse a whole new method of making the menu loop?
Did you initialize option ? you seem to be commenting //system("pause"); .Are you really using a standard compiler?
>>The problem seems to be if I input strings or characters, it crashes
First get whatever input in a temporary string and then use strtol to get your option
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.