I realize this is probably really stupid

Started by
4 comments, last by maxd gaming 20 years, 8 months ago
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)
The Untitled RPG - |||||||||| 40%Free Music for your gamesOriginal post by capn_midnight 23yrold, is your ass burning from all the kissing it is recieving?
Advertisement
semicolons dont seem to be the problem
The Untitled RPG - |||||||||| 40%Free Music for your gamesOriginal post by capn_midnight 23yrold, is your ass burning from all the kissing it is recieving?
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]
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
switch (input){    void playgame()    {  


You can't define a function inside of another function.


All you will ever need to know.

[edited by - CodeMunkie on August 13, 2003 6:43:06 PM]
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
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]
An ASCII tetris clone... | AsciiRis
Thanks
The Untitled RPG - |||||||||| 40%Free Music for your gamesOriginal post by capn_midnight 23yrold, is your ass burning from all the kissing it is recieving?

This topic is closed to new replies.

Advertisement