Thread: Error: decleration expected after usage of SWITCH/BREAK

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    16

    Error: decleration expected after usage of SWITCH/BREAK

    Hi! I have to make a 2D home plan of my house for an assignment and run the user through all the different rooms, by letting them chose the direction they want to go. As I'm not that far yet, I've already defined all the 7 different rooms by means of using a structure. now I want the color of the background and text to change with every room and inserted these settings in the room declerations. I decided since there were only 5 expectations of the room colours to use SWITCH/BREAKS in a function to color the rooms, but I seem to get an error after everything I try: decleration expected right before my ColorRoom function ends. I'm completely stuck and help would be really appreciated

    This is my code so far:

    Code:
     
    //Required System Files
    #include <stdio.h>
    #include <stdlib.h>
    
    //Global Definitions
    #define North = 1
    #define East = 2
    #define South = 3
    #define West = 4
    
    //Global Structure Type Definition
    typedef struct 
    {				 										//Define new Structure Type
    char Description[200]; 									//Use up to 200 characters for description string
    unsigned int Color;										//Assign room background and text colors using hexadecimal coding in system()
    unsigned int Exit[4]; 									//Use 4 possible different values for Exit array
    }Location; 												//Call this structure type: Location
    
    //Global Location Type Variable Definition
    Location Room[7]; 										//Create 7 Location type Global structures called Room ’s
    
    //Function definitions
    void SetupRooms();										//define the setup function
    void DescribeRoom(int number);							//define's the room description
    void DescribeExits(int number);							//define's the funtion for the exit descriptions
    int GetDirection(int number);							//Roomnumber has to be given to determine which direction possible, this will return a value as well
    void ColorRoom(int number);								//Color the room the appropriate color
    
    //Main Function
    void main()
    {
    unsigned int RoomNumber = 1; 							//Set up starting room number as 1, the entrance
    unsigned int Direction;
    
    SetupRooms(); 											//Set up Roomstructures
    	//while(1){											//loop forever
    			system("cls"); 								//Clear Screen
    			ColorRoom(RoomNumber);						//Color the room
    			//DescribeRoom(RoomNumber); 					//Describe current Room
    			//DescribeExits(RoomNumber); 					//Describe current Room Exits
    			//Direction = GetDirection(RoomNumber); 		//Get direction to go in
    			//if (Direction == 99) exit (0); 				//Exit prog if 99 is returned
    			//if (Direction > 0) RoomNumber = Direction ;	//Set current Roomnumber
    	//}
    }
    
    void ColorRoom(int n)
    {
    unsigned int XY = Room[n].Color;
    	switch(XY){											//5 expected values, use switch/breaks
    					case 0x6F:								//test if color is Brown
    							system("color 6F");				//make brown
    							break;
    					case 0x2F:								//test if green
    							system("color 2F");
    							break;
    					case 0x90:								//test if blue
    							system("color 90");			
    							break;
    					case 0xF0:								//test if white
    							system("color Fo");		
    							break;
    					case 0x01:								//test if gray
    							system("color 01");
    							break;
    	}
    }
    							
    }
    
    void SetupRooms()
    {
    //MY ROOM 1 DEFINITION
    strcpy(Room[1].Description, "Entrance");
    Room[1].Color = 0x90;										//Color description room, blue
    //Room[1].Exit[North]= 0; 								//Only exit is towards soutgh
    //Room[1].Exit[East]= 0;
    //Room[1].Exit[South]= 2;
    //Room[1].Exit[West]= 0;
    
    //MY ROOM 2 DEFINITION
    strcpy(Room[2].Description, "Big Living Room");
    Room[2].Color = 0x90;
    //Room[2].Exit[North] = 1;
    //Room[2].Exit[East] = 3; 									
    //Room[2].Exit[South] = 5;
    //Room[2].Exit[West] = 6;
    
    //MY ROOM 3 DEFINITION
    strcpy(Room[3].Description, "Kitchen");
    Room[3].Color = 0xF0;									//Color kitchen is white    !!!!!!!!!!!!!!!!!!!!!!!!!! klopt dit F0???? KIJK NA HEXADECIMALN
    //Room[3].Exit[North] = 0;								//No exits to North and East
    //Room[3].Exit[East] = 0; 									
    //Room[3].Exit[South] = 4;
    //Room[3].Exit[West] = 2;
    
    //MY ROOM 4 DEFINITION
    strcpy(Room[4].Description, "Patio");
    Room[4].Color = 0x2F;										//Color Patio is green
    //Room[4].Exit[North]= 3;	
    //Room[4].Exit[East]= 0; 									//No exits to east and south
    //Room[4].Exit[South]= 0;
    //Room[4].Exit[West]= 5;
    
    //MY ROOM 5 DEFINITION
    strcpy(Room[5].Description, "Computer room");
    Room[5].Color = 0x01;										//Color Computer room is gray
    //Room[5].Exit[North]= 2;	
    //Room[5].Exit[East]= 4; 									//No exits to south and west
    //Room[5].Exit[South]= 0;
    //Room[5].Exit[West]= 0;
    
    //MY ROOM 6 DEFINITION
    strcpy(Room[6].Description, "Garden");
    Room[6].Color = 0x2F;										//Color garden is green
    //Room[6].Exit[North]= 0;	
    //Room[6].Exit[East]= 2; 									//No exits to north and west
    //Room[6].Exit[South]= 7;
    //Room[6].Exit[West]= 0;
    
    //MY ROOM 7 DEFINITION
    strcpy(Room[7].Description, "Shed");
    Room[7].Color = 0x6F;										//Color Shed is brown
    //Room[7].Exit[North]= 6;	
    //Room[7].Exit[East]= 0; 									//Only exit back to north
    //Room[7].Exit[South]= 0;
    //Room[7].Exit[West]= 0;
    }
    Thanks!

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Code:
    void ColorRoom(int n)
    {
    unsigned int XY = Room[n].Color;
    	switch(XY){											//5 expected values, use switch/breaks
    					case 0x6F:								//test if color is Brown
    							system("color 6F");				//make brown
    							break;
    					case 0x2F:								//test if green
    							system("color 2F");
    							break;
    					case 0x90:								//test if blue
    							system("color 90");			
    							break;
    					case 0xF0:								//test if white
    							system("color Fo");		
    							break;
    					case 0x01:								//test if gray
    							system("color 01");
    							break;
    	}
    }
    							
    }
    You have an extra curly brace. Remove that. Also, it's int main(void), and you need to return an integer at the end, usually 0. Lastly, since you use strcpy, you need to include string.h.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Take a look at the subroutine... Your braces don't match.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    16
    I just put in everything u guys said, and it works like a charm, thanks so much!

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Checking indentation would have caught that.
    Code:
    	}
    }
    							
    }
    is suspicious because two of the braces are in the same column.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 08:29 PM