My menu program won't stop looping

This is a discussion on My menu program won't stop looping within the C Programming forums, part of the General Programming Boards category; Please help me I am an absolute begginner. I am writing a program that allows a user to enter options ...

  1. #1
    Unregistered
    Guest

    My menu program won't stop looping

    Please help me I am an absolute begginner. I am writing a program that allows a user to enter options 1 to 5 on a menu. The choice they make has to be an integer. I have an no problems yet my problem starts when a letter is keyed in my program goes into a loop. Please can someone help me with the code i need to stop this happening. I am sorry if i have not described what is happening to clearly i am still learning the correct terminology. This program is part of my HNC in computing so i'm dead if i don't get it sorted thanks

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > Please can someone help me with the code i need to stop this happening.

    Yes - I detect telepathically that you don't increment your loop variable.

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    What about if you wrote some code, that we (programmers) could help you.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Let me guess, your code looks like this....
    Code:
    for (;;)
    {
     scanf ("%d", &i);
     switch (i)
     {
      case 1:
       // stuff
      break;
      case 2:
       // stuff
      break;
      case 3:
       // stuff
      break;
      case 4:
       // stuff
      break;
      case 5:
       // stuff
      break;
      default:
      break;
     } // end switch
    } // end for
    Just flush the input buffer after your scanf...
    Code:
    for (;;)
    {
     scanf ("%d", &i);
     for (; cetchar () != '\n';);
     switch (i)
     {
    // ...
    It's not the best solution in the world, but it works.
    Last edited by QuestionC; 01-26-2002 at 04:33 PM.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't stop my program at zero (Loan Table)
    By beachsidefl321 in forum C Programming
    Replies: 10
    Last Post: 06-24-2009, 10:14 PM
  2. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 02:42 AM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  4. add your program to start menu ?
    By Anddos in forum Windows Programming
    Replies: 6
    Last Post: 04-17-2008, 05:15 AM
  5. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21