different values in while using enum?

This is a discussion on different values in while using enum? within the C++ Programming forums, part of the General Programming Boards category; Hi. I was wondering is there anyway i can put in different value into my while structure so i don't ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    28

    different values in while using enum?

    Hi.
    I was wondering is there anyway i can put in different value into my while structure so i don't have to make more switches?
    Thanks alot.

    p.s. my user defined types in the enum i was thinking could be used in the while structure .




    Code:
    #include <iostream>
    using namespace std;
    
    
    void started ( void );            // function prototype :1
    
    
    
    int option1;
    
    
    int main()
    {
    
      cout <<"Hi welcome to the driving program" << endl
           <<"\nPlease press: 2 to start engine" << endl;
    
      while ( ( option1 = cin.get() ) != EOF ) {               // put in different  option in while structure.
    
         switch ( option1 ) {
    
            case '2':
               started();
               break;                                           // to exit switch
       }
     }
    
    return 0;
    }
    
    void started ( void )            // function def :1
    {
       cout << "Engine started" << endl;
    }
    
    
    
    
    //enum GEARS { reverse, first, second, third, fourth, fifth }; // starts at 0 and increments by 1

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Hmm donīt really understand your problem (be more specific) but I try anyway ^^. A while statement look like this
    Code:
    while(some condition)
    {
    statements;
    }
    The statements will executed as long as some condition is avaluated as true. To exit the while loop you have to
    • some condition must be evaluated as false
    • unconditional branch with e.i. break or goto (usually not recommended)


    Here is some sample code
    Code:
    #include <iostream>
    
    int main()
    {
    bool isLooping = true;
    int counter = 1;
    while(isLooping)
    {
    	std::cout << "Counter is now: " << counter << std::endl;
    	if (counter == 5)
    		isLooping = false;//or just break;
    	++counter;
    }
    return 0;
    }
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic question on enum
    By MasterM in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2009, 09:16 PM
  2. Replies: 2
    Last Post: 11-19-2008, 01:36 PM
  3. IRC-type logger with files based on three values
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 08-27-2008, 04:42 PM
  4. Testing Floating Point Return Values
    By jason_m in forum C Programming
    Replies: 5
    Last Post: 08-15-2008, 01:37 PM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM

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