Thread: Menu Loop

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    1

    Menu Loop

    Hello. I am trying to do a try.. catch statement and where there is exception error thrown, i want it to go back to the beginning. I have done the following, but I know I have made a mistake somewhere, but am stumped. Please assist me here

    here is the code :

    Code:
    #include <iostream>
    using namespace std;
    
    void printList(short list[]);
    
    int main()
    {
       short n[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
       int index=0, value;
    
       printList(n);
    
       while (index != -1)
       {
             try
             {
              cout << "Enter array index (0..9) to update (-1 to quit): ";
              cin >> index; 
              
              if (index > 10)
                 throw 1;
                     
              
              else if (index == -1)
                 break;
              }
              
              catch (int index)
              {
                    cout << "Exception thrown" << endl;
              }
              
              cout << "Enter new value:  ";
              cin >> value;
    
              n[index] = value;
              printList(n);
              
       }
       return 0;
    }  
    
    void printList(short list[])
    {
       cout << "List: ";
       for (int i=0; i<10; i++)
           cout << list[i] << " ";
       cout << endl; 
    }
    thank you all !
    Last edited by Salem; 11-07-2006 at 06:31 AM. Reason: Remove font colour/size abuse

  2. #2
    Registered User SpaceCadet's Avatar
    Join Date
    Oct 2006
    Posts
    23
    Code:
              catch (int index)
              {
                    cout << "Exception thrown" << endl;
                    continue;
              }
    All questions are easy. The answers cause the problem...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. return to start coding?
    By talnoy in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2006, 03:48 AM
  3. loop needed also how to make input use letters
    By LoRdHSV1991 in forum C Programming
    Replies: 3
    Last Post: 01-13-2006, 05:39 AM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  5. Delet Frequency in linked list
    By swishiat.com in forum C Programming
    Replies: 16
    Last Post: 12-13-2003, 02:05 AM