#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    12

    Question Simple Enumeration


    Hello,
    I am just trying to get a good grasp on enums. I created this code just to test to see if i knew how to do it. But i got an error having to do with the ">>" operator. Anyways.. this is wat i have, anyhelp would be greatly appreaciated. Thanks.
    PHP Code:
    #include <iostream.h>

    int main()
    {
        
    enum Day {MON 1TUEWEDTHUFRISATSUN}dayoff
        
    cout << "What day do you want off?";
        
    int x;
        
    cin >> dayoff(x);
        if (
    dayoff == 1)
            
    cout << "Mon";
        else 
            
    cout << "Tue- sun";
        return 
    0;

  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Try this instead:
    Code:
    #include <iostream.h>
    
    enum Day {
            MON=1,
            TUE,
            WED,
            THU,
            FRI,
            SAT,
            SUN};
    
    int main() {
            int x;
    
            cout << "What day do you want off?";
            cin >> x;
            switch(x) {
                    case MON:
                            cout << "Monday";
                            break;
                    case TUE:
                            cout << "Tuesday";
                            break;
                    case WED:
                            cout << "Wednesday";
                            break;
                    case THU:
                            cout << "Thursday";
                            break;
                    case FRI:
                            cout << "Friday";
                            break;
                    case SAT:
                            cout << "Saturday";
                            break;
                    case SUN:
                            cout << "Sunday";
                            break;
                    default:
                            cout << "I don't understand your answer";
                            break;
            }
            return 0;
    The reason why you are getting errors is because when you enum a set of values, that is exactly what they are, values. They aren't types so you can not use them in that fashion. Think of it as the true & false values. You can't say cin >> false; because false is a value.
    Make sense?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    12
    allright thanks man that worked :)

IMN logo majestic logo threadwatch logo seochat tools logo