Not sure what the exact title should be. But at a point in my text game. I want to have multiple selections. But whenever I put the code (shown below), compile the program, and run it I get this. It goes through my main menu, new game, all the stuff up to where you make the first decision in the game. Then instead of choosing one or the other, it runs through the first one. Then through the second. I'm stuck here and hoping somebody could enlighten me. Please don't say stuff like "Oooh your using this when you should be using thing" and chop through my code. Please just try to help me with the problem at hand.

Here is the entire source so far.

#include <iostream>
#include <Windows.h>
#include <stdlib.h>
using namespace std;

char startmenu[50];
char gamechoices[50];
int main()
	
{
  HANDLE  hConsole;
	int startmenucolour;
	int gamecolour;

	
  hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

  // you can loop k higher to see more color choices
  startmenucolour = 249;
  gamecolour = 240;
  {
    // pick the colorattribute k you want
    SetConsoleTextAttribute(hConsole, startmenucolour);
    cout << "Xelzia: Story of Kings" << endl;
  }
  cout << "New Game, Load Game, Quit Game, or About?";
  cin.getline (startmenu, 50);
 
  do {
	  system ("cls");
	  cout <<"You wish to load a game." <<endl;
	  cout <<"Since there is only 1 save slot I will now recall your most recent adventure" <<endl; //Unfinished!!

  }
  while (startmenu == "Load game" || startmenu == "Load");

  
  
  
  
  
  
  do {
	  system ("cls");
	  cout <<"You have chosen to start a new adventure" <<endl;
	  cout <<"When you save this game, your previous one will be overwritten"<<endl;
	  cout <<"Controls: Enter to continue, type for commands." <<endl;
	  cout <<"Recent text will be deleted when you make a choice in the game." <<endl;
	  Sleep (10000);
	  system ("cls");
	  SetConsoleTextAttribute(hConsole, gamecolour);
	  cout <<"You are a poor peasant living in the kingdom of Drakinrot,";
	  cin.get();
	  cout <<"Sleeping in your torn up dirty leather sleeping bag";
	  cin.get();
	  cout <<"Enjoying a good nights rest after a hard day of work.";
	  cin.get();
	  cout <<"Your last one... For a while...";
	  cin.get();
	  cout <<"Suddenly a fully armed guard rushes into your corridor pushing everyone out of the way";
	  cin.get();
	  cout <<"Without opening your eyes you can tell the bastard is right in front of you";
	  cin.get();
	  cout <<"What do you do?" <<endl;
	  cin.getline (gamechoices, 50);
	
		  
	  
	  if (gamechoices == "Attack" || gamechoices == "fight" || gamechoices == "kill");
	  do {
		  system ("cls");
		  cout <<"You jump up charging at the soldier with no weapon in your hands";
		  cin.get();
		  cout <<"The soldier laughs and grabs you by the neck";
		  cin.get();
		  cout <<"Soldier: Ha, you think it would be that easy?";
		  cin.get();
		  cout <<"You: I was hoping as much.";
		  cin.get();
		  cout <<"He spits on your face then grins.";
		  cin.get();
		  cout <<"Soldier: Now I have orders to take you to the king. That's what I'm going to do.";
		  cin.get();
		  cout <<"Soldier: Lets go, now!";
	  } while (gamechoices == "Attack" || gamechoices == "fight" || gamechoices == "kill");

	  if (gamechoices == "Look" || gamechoices == "look at" || gamechoices == "Sit up" || gamechoices == "dont attack" ||
		  gamechoices == "don't attack" || gamechoices == "talk" || gamechoices == "ask" || gamechoices == "question");
	  do {
		  system("cls");
		  cout <<"You slowly sit up and look at the armed man";
		  cin.get();
		  cout <<"The soldier looks down at you almost in pity.";
		  cin.get();
		  cout <<"Soldier: I have strict orders from the king to bring you to him";
		  cin.get();
		  cout <<"You look at the soldier with a questioning look";
		  cin.get();
		  cout <<"Soldier: I have no idea either, he didn't tell me anything else.";
		  cin.get();
		  cout <<"Soldier: So are you coming?";
		  cin.get();
		  cout <<"You rush to your feet, wrap yourself in your cloak and follow behind";
	  } while (gamechoices == "Look" || gamechoices == "look at" || gamechoices == "Sit up" || gamechoices == "dont attack" ||
		  gamechoices == "don't attack" || gamechoices == "talk" || gamechoices == "ask" || gamechoices == "question");
		  






  }
  while (startmenu == "New game" || startmenu == "New");








  
  cin.get(); // wait
  return 0;
}

Here is the first choice part.

if (startmenu == "new" || startmenu == "new game" || startmenu == "newgame");
  do {
	  system ("cls");
	  cout <<"You have chosen to start a new adventure" <<endl;
	  cout <<"When you save this game, your previous one will be overwritten"<<endl;
	  cout <<"Controls: Enter to continue, type for commands." <<endl;
	  cout <<"Recent text will be deleted when you make a choice in the game." <<endl;
	  Sleep (10000);
	  system ("cls");
	  SetConsoleTextAttribute(hConsole, gamecolour);
	  cout <<"You are a poor peasant living in the kingdom of Drakinrot,";
	  cin.get();
	  cout <<"Sleeping in your torn up dirty leather sleeping bag";
	  cin.get();
	  cout <<"Enjoying a good nights rest after a hard day of work.";
	  cin.get();
	  cout <<"Your last one... For a while...";
	  cin.get();
	  cout <<"Suddenly a fully armed guard rushes into your corridor pushing everyone out of the way";
	  cin.get();
	  cout <<"Without opening your eyes you can tell the bastard is right in front of you";
	  cin.get();
	  cout <<"What do you do?" <<endl;
	  cin.getline (gamechoices, 50);
  } while (startmenu == "new" || startmenu == "new game" || startmenu == "newgame");
	
		  
	  
	  if (gamechoices == "Attack" || gamechoices == "fight" || gamechoices == "kill");
	  do {
		  system ("cls");
		  cout <<"You jump up charging at the soldier with no weapon in your hands";
		  cin.get();
		  cout <<"The soldier laughs and grabs you by the neck";
		  cin.get();
		  cout <<"Soldier: Ha, you think it would be that easy?";
		  cin.get();
		  cout <<"You: I was hoping as much.";
		  cin.get();
		  cout <<"He spits on your face then grins.";
		  cin.get();
		  cout <<"Soldier: Now I have orders to take you to the king. That's what I'm going to do.";
		  cin.get();
		  cout <<"Soldier: Lets go, now!";
	  } while (gamechoices == "Attack" || gamechoices == "fight" || gamechoices == "kill");

	  if (gamechoices == "Look" || gamechoices == "look at" || gamechoices == "Sit up" || gamechoices == "dont attack" ||
		  gamechoices == "don't attack" || gamechoices == "talk" || gamechoices == "ask" || gamechoices == "question");
	  do {
		  system("cls");
		  cout <<"You slowly sit up and look at the armed man";
		  cin.get();
		  cout <<"The soldier looks down at you almost in pity.";
		  cin.get();
		  cout <<"Soldier: I have strict orders from the king to bring you to him";
		  cin.get();
		  cout <<"You look at the soldier with a questioning look";
		  cin.get();
		  cout <<"Soldier: I have no idea either, he didn't tell me anything else.";
		  cin.get();
		  cout <<"Soldier: So are you coming?";
		  cin.get();
		  cout <<"You rush to your feet, wrap yourself in your cloak and follow behind";
	  } while (gamechoices == "Look" || gamechoices == "look at" || gamechoices == "Sit up" || gamechoices == "dont attack" ||
		  gamechoices == "don't attack" || gamechoices == "talk" || gamechoices == "ask" || gamechoices == "question");
		  






  
  








  
  cin.get(); // wait
  return 0;
}

Please help, I've tried multiple different combos. Can't seem to get it to work. Being a little ill minded.

Recommended Answers

All 3 Replies

I'm not sure if this is your problem, but with some methods of getting input, stuff will be left in the input stream, or error bits will be set. You must clear the errors and ignore newlines. Personally I prefer to sync() the stream with the source of characters.

You're skipping your if loops:

if (gamechoices == "Attack" || gamechoices == "fight" || gamechoices == "kill");

The semicolon ";" at the end terminates the if statement. You need to place anything that will be executed within your if loops within brackets "{ }". It's a common mistake since intuition tells us that semicolon means "end line", when it actually means "end of statement". So, what's happening is your if statements are checking, and, if true, doing nothing, ending, then executing your do loop.

So I tried deleting all the semicolons. But now when I type "new game" for a new game. Nothing happens. Just shows the text entry, then if I type it in again the program closes, ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.