Thread: Char/Int problems.....

  1. #1
    Unregistered
    Guest

    Angry Char/Int problems.....

    In the program i am writing, it asks the user to type 1 for this menu, 2 for this, and 3 for another. If the user types anything but 1, 2, or 3, it will go back to the previous menu instead. However i have a problem. If the user types a letter instead of a number, the program simply terminates. To fix this i tried making the variable to hold the menu choice a Char. Now when i did this, it would go back to the previous menu correctly, but if the user typed 1 2 or 3 to go do different menus, it wouldn't go to them...it would just go back to the previous menu instead, without performing the functions called by menu 1 2 or 3. This is really ........ing me off.. any ideas?

  2. #2
    Unregistered
    Guest
    Nevermind, i figured it out
    I just included <string> and defined the menu choice variable as a string.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    63
    Maybe if you want you can try and use a character array, instead of using a string, therefore giving a little bit more protection for what the user inputs.
    tudehopet uses Borland Compiler 5.5
    and Visual C++ 6.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM