C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 11th, 2002, 08:17 PM
Optix Optix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 36 Optix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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;


Reply With Quote
  #2  
Old July 12th, 2002, 08:19 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
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?

Reply With Quote
  #3  
Old July 12th, 2002, 03:22 PM
Optix Optix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 36 Optix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
allright thanks man that worked

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Simple Enumeration


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT