• ### Announcements

#### Archived

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

# Another newbie question

## Recommended Posts

##### Share on other sites
Your ''if'' statements at the bottom are a little off.

if(game() == 2)
{
if(gamea() == 2)
{
gameb();
}
}

Try this out.

##### Share on other sites
you are missing lots of break;''s on your switch statements

##### Share on other sites

This code works:

  #include <iostream.h>int game();int gamea();int gameb();int game(){	int first;	cout << endl << endl;	cout << "You are in a locked room full of stores for the soldiers of the base." << endl; 	cout << "What are you going to do? Enter a number." << endl;  	cout << "Enter 1 in order to try to force the door." << endl;  	cout << "Enter 2 in order to try to go through the ventilation." << endl;   	cout << "Enter 3 in order to pretend to be ill and call for the guard to check." << endl << endl;    cout << "Enter: ";	cin >> first;	switch(first)	{		case 1:  			cout << "The door is made of titanium and has a really tuff lock." << endl;     		cout << "You don't think you can open it." << endl;         	cout << "GAME OVER";		break;		case 2:  			cout << "Yeah that's it you made it through the ventilation." << endl;     		cout << "Thank god you were on a diet before you were captured.";		break;		case 3:  			cout << "Nope. Didn't work. The guard understood your trick and started laughing." << endl;     		cout << "You must try something else." << endl;         	cout << "GAME OVER";		break;		default:  			cout << "Wrong number";		break;	}	return first;}int gamea(){	int second;	cout << endl << endl;	cout << "Good you made it through the ventilations. Now you are in a hall." << endl; 	cout << "You can either go right or left." << endl;  	cout << "Enter 1 for right or 2 for left." << endl;   	cout << "Enter: ";	cin >> second;		switch(second)	{		case 1:  			cout << "Right didn't appear to be the right choice, a surveilance" << endl;     		cout << "camer caught a glimpse of you. That was it the guards caught you." << endl;         	cout << "GAME OVER";		break;		case 2:  			cout << "Congratulations. You are really good at this." << endl;     		cout << "An idiot must have left this way unguarded." << endl;       		cout << "You made your way out of the prison facility of the base.";		break;		default:  			cout << "Wrong number";		break;	}	return second;}int gameb(){	int third;	cout << endl << endl;	cout << "You are now in the Prison yard. You approach the exit door" << endl; 	cout << "but see that it requires a password." << endl;  	cout << "Fortunately it gives you a hint." << endl;   	cout << "The password is (2*2*8)-30." << endl;   	cout << "Enter password: ";	cin >> third;		switch(third)	{		case 2:  			cout << "Oh boy you are good. You found the password. You made it" << endl;     		cout << "completely out of the prison and into the main base.";		break;		default:  			cout<<"Wrong password.";         	cout << "GAME OVER";    	break;	}	return third;}int main(){	cout << "eeeeeee" << endl;	cout << "eeeeeee" << endl;	cout << "ee" << endl;	cout << "ee" << endl;	cout << "ee" << endl;	cout << "ee" << endl;	cout << "eeeeeee 11111" << endl;	cout << "eeeeeee 11 11" << endl;	cout << "ee 11 11" << endl;	cout << "ee 11" << endl;	cout << "ee 11" << endl;	cout << "ee 11" << endl;	cout << "eeeeeee 11" << endl;	cout << "eeeeeee 11" << endl;	if(game() == 2)	{		if(gamea() == 2)  			gameb();	}		return 0;}

[edited by - Pepe on March 22, 2002 12:36:33 PM]

##### Share on other sites
You will need to add a break after calling gamea() in case 2 of the int game() func. Otherwise when execution leaves the scope of gamea() it will return to game() and fall through to case 3.

Err you will also need to do the same thing after calling gameb() in case 2 of gamea().

[edited by - dviator on March 22, 2002 12:38:47 PM]

##### Share on other sites
thanks but I understand that if I continue this way I will get full of if staements.Please tell me another way to do it properly.

##### Share on other sites
also what is this:<

##### Share on other sites
http://www.gamedev.net/community/forums/topic.asp?topic_id=86297

You are moving forward in game design ...you have figured out that if you keep with your current design, your program will be a huge ifelse, ifelse... program.

Sabre gives you a better design.

• ### Forum Statistics

• Total Topics
627719
• Total Posts
2978790

• 9
• 21
• 14
• 12
• 42