Archived

This topic is now archived and is closed to further replies.

I realize this is probably really stupid

This topic is 5237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

but why doesnt this work?
#include <iostream.h>
#include <conio.h>


int start()
{  	 
  int input;	  
  cout<<"1. Play game \n";	
  cout<<"2. Load game \n";	
  cout<<"3. Play multiplayer \n";	
  cout<<"4. Exit \n";	
  cin>>input;	 
  switch (input)	
  {	

	    void playgame()
	  {
		  int playinput;
		  cout<<"1. Look around \n";
		  cout<<"2. Turn on the radio \n";
		  cout<<"3. Watch TV \n";
		  cout<<"4. Exit Game \n";
		  cin>>playinput;
		  switch (playinput)
		  case 1: 
			  cout<<"You look around";  //Declare and add a function for look()
			  break;
		  case 2:
			  cout<<"You Turn On The Radio"; //Declare and add a function for radio()
			  break;
		  case 3:
			  cout<<"You watch TV"; //Declare and add a function for tv()
		  default:
			  cout<<"Error";
	  }

   case 1: playgame();
	   break;	 
   case 2:
	 cout<<"You can''t load a game";	
	 start();
        break;	
   case 3:	      
        cout<<"You can''t play multiplayer";
		start();
	  break;	
   case 4:
        return 0;   
  default: 	  
        cout<<"Error, bad input, quitting";	
  }
  return 0;
}


}




int main()

{
	start();

	return 0;
}
 
--------------------Configuration: Cpp1 - Win32 Debug-------------------- Compiling... Cpp1.cpp \C ++\switchcase\Cpp1.cpp(17) : error C2601: ''playgame'' : local function definitions are illegal \C ++\switchcase\Cpp1.cpp(56) : error C2143: syntax error : missing '';'' before ''}'' \C ++\switchcase\Cpp1.cpp(66) : error C2143: syntax error : missing '';'' before ''return'' \C ++\switchcase\Cpp1.cpp(67) : error C2143: syntax error : missing '';'' before ''}'' Error executing cl.exe. Cpp1.exe - 4 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
No brackets around your switch statement... Please, please , check basic syntax before posting without even an explanation of what is wrong .

[edit] Referring to the second switch in the first one.

[edited by - Raloth on August 13, 2003 6:36:57 PM]

Share this post


Link to post
Share on other sites
Yes codeMunkie is right ... it should also be more like this...
#include <iostream.h>
#include <conio.h>
void playgame()
{
int playinput;

cout<<"1. Look around \n";
cout<<"2. Turn on the radio \n";
cout<<"3. Watch TV \n";
cout<<"4. Exit Game \n";
cin>>playinput;

switch (playinput)
{
case 1:
cout<<"You look around"; //Declare and add a function for look()

break;
case 2:
cout<<"You Turn On The Radio"; //Declare and add a function for radio()

break;
case 3:
cout<<"You watch TV"; //Declare and add a function for tv()

default:
cout<<"Error";
}
}

int start()
{
int input;
cout<<"1. Play game \n";
cout<<"2. Load game \n";
cout<<"3. Play multiplayer \n";
cout<<"4. Exit \n";
cin>>input;
switch (input)
{

case 1:
playgame();
break;
case 2:
cout<<"You can't load a game";
start();
break;
case 3:
cout<<"You can't play multiplayer";
start();
break;
case 4:
return 0;
default:
cout<<"Error, bad input, quitting";
}
return 0;

}

int main()
{
start();
return 0;
}


Edit: (i should probably tell you what i changed) you had an extra closing semicolon or two (around your second switch statement) you were declaring your playgame() function inside your start() function (as somebody said that's not legal by any means) and as somebody else said you hadn't put braces around the second switch statement.

An ASCII tetris clone... | AsciiRis

[edited by - Tiffany Smith on August 13, 2003 6:56:17 PM]

Share this post


Link to post
Share on other sites