New function problem.. anyone help?

This is a discussion on New function problem.. anyone help? within the C++ Programming forums, part of the General Programming Boards category; I recoded my function, but it is still stopping my program after the user enters the input. The function should ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    19

    Question New function problem.. anyone help?

    I recoded my function, but it is still stopping my program after the user enters the input. The function should return the char value if the user enters a valid letter (A through I or X). But, it just stops after the input is entered.

    Code:
    char accept_item_code ()
    {
       char c;
       bool valid = false;
    
       cout << endl << "--------------------" << endl;
       cout << "Enter product code: ";
       cin >> c;
       c = toupper(c);
       cout << c;
       cout << endl;
       while (!valid)
       {
          if (c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E')
          {
             valid = true;
          }
          else if (c == 'F' c == 'G' || c == 'H' || c == 'I' || c == 'X')
          {
             valid = true;
          }
          else
          {
             cout << "!!! Invalid product code" << endl << endl
                  << "Enter product code: ";
             cin >> c;
             c = toupper(c);
             cout << endl;
          }
       }
    
       return c;
    }

    Josh Stevanus
    jrstevan@svsu.edu

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Where is the rest of your code? What do you expect it to do? The function you posted returns after valid input, so whatever is supposed to happen is happening in code elsewhere.


    Also notice a missing || in your code:
    Code:
    else if (c == 'F' || c == 'G' || c == 'H' || c == 'I' || c == 'X')

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2008, 06:33 AM
  2. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 01:36 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM

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