Thread: enumeration with switch case?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Shadow12345
    Guest

    enumeration with switch case?

    Here is the planet class and constructor which randomly determines the planets status:
    Code:
    class Planet {
    public:
    	Planet();
    	enum { Ally, Governemnt, Neutral } Status;	//USED TO DETERMINE THE PLANETS STATUS IN THE GAME
    private:
    };
    
    Planet::Planet() {
    	int RandomStatus = rand()%3;	//RANDOMLY SETS THE STATUS OF THE PLANET
    	switch(RandomStatus) {
    	case 0:
    		Status = Ally;
    		break;
    	case 1:
    		Status = Governemnt;
    		break;
    	case 2:
    		Status = Neutral;
    		break;
    	default:
    		Status = Neutral;
    	}
    }
    Here i have an instance of the planet class
    Code:
    Planet *Planet1 = new Planet;
    and lastly I have a thing that tests the planet's status to make sure it works:
    Code:
    	char *AllyStatus = "The Planet is sided with the player";
    	char *GovtStatus = "The planet is sided with the goverment";
    	char *Neutral = "The planet is neutral";
    
     while(!done)         // Loop That Runs While done=FALSE
     {
    	 switch(Planet1->Status) {
    	case Ally:
    		TextOut(hDc, 0, 0, AllyStatus, sizeof(AllyStatus));
    		break;
    	case Government:
    		TextOut(hDc, 0, 0, GovernmentStatus, sizeof(GovernmentStatus));
    		break;
    	case Neutral:
    		TextOut(hDc, 0, 0, Neutral, sizeof(Neutral));
    		break;
    	default:
    		break;
    	 }
    ...
    ...
    ...
    For some reason I get these errors:
    --------------------Configuration: lesson1 - Win32 Debug--------------------
    Compiling...
    Lesson1.cpp
    C:\Documents and Settings\04thibaultc\Desktop\9 - 26 - 02 doens't compile\Lesson1.cpp(738) : error C2065: 'Ally' : undeclared identifier
    C:\Documents and Settings\04thibaultc\Desktop\9 - 26 - 02 doens't compile\Lesson1.cpp(738) : error C2051: case expression not constant
    C:\Documents and Settings\04thibaultc\Desktop\9 - 26 - 02 doens't compile\Lesson1.cpp(741) : error C2065: 'Government' : undeclared identifier
    C:\Documents and Settings\04thibaultc\Desktop\9 - 26 - 02 doens't compile\Lesson1.cpp(741) : error C2051: case expression not constant
    C:\Documents and Settings\04thibaultc\Desktop\9 - 26 - 02 doens't compile\Lesson1.cpp(742) : error C2065: 'GovernmentStatus' : undeclared identifier
    C:\Documents and Settings\04thibaultc\Desktop\9 - 26 - 02 doens't compile\Lesson1.cpp(744) : error C2051: case expression not constant
    C:\Documents and Settings\04thibaultc\Desktop\9 - 26 - 02 doens't compile\Lesson1.cpp(749) : warning C4065: switch statement contains 'default' but no 'case' labels
    Error executing cl.exe.

    lesson1.exe - 6 error(s), 1 warning(s)


    That's a lot of errors! Ouch!
    Last edited by Shadow12345; 09-26-2002 at 08:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 09:42 AM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  5. rand()
    By serious in forum C Programming
    Replies: 8
    Last Post: 02-15-2002, 02:07 AM