How to make a choose your own path game...

Pages: 12
oh well, then i will erase the post
The task is not so "beginner" if you want to do it right. Do you know about reading from files, vectors, and classes? I do not recommend making a huge switch-case statement.
come on man, let him share his ideas. dont be a tool! after all it might work! do you know that beating down programmers isnt how a programmer gets the inspiration to use his imagination?telling him his ideas are wrong or suck?? Just leave if your gonna do that.
Is that at me?

I'm more than happy to help, and I think the questions you have already asked shows you see something wrong with the proposed solution:
This seems like it would work but, how do I get it to ask more questions if they pick 1 or 2?


The answer is to code them in. Then code in the next switch case, the next, and the next.

So if you want to spend your days doing switch case, go ahead.

I'm not try to brag, but I can say that I wrote this program in less than 100 lines, and there is no limit (other than hardware), to the story that you could write.

But it isn't "beginner", so I'm trying to get an idea of what "relatively new to c++" means.
But still let him share. I wont get any better if I only stick to beginner stuff.
closed account (3TXyhbRD)
Stop twisting them words! Nobody said "stick to beginner stuff". LowestOne was suggesting that this problem is not very beginner-ish meaning it should be in the General C++ Programming section since a real solution is beyond a huge list of if.. else statements.

2nd, nobody is forcing anyone to "not post" unless he's a spam bot/troll but that's admins ban hammer.
Last edited on
Personally, I'd use what Andrei suggested.

Here's a little mock-up:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//includes.
#include <iostream>
#include <conio.h> //Included for _kbhit()/_getch()

//Function prototypes.
void wait( char *message );
void forest();
void city();
void prison();

int main()
{
	int choice = 0;
	
	std::cout << "Where do you want to go?\n";
	std::cout << "1. To the forest.\n";
	std::cout << "2. To the city.\n";
	std::cout << "3. To the prison.\n";

	std::cout << "\nChoice: ";
	std::cin >> choice;

	switch( choice )
	{
		case 1:
			forest();
			break;
		
		case 2:
			city();
			break;
		
		case 3:
			prison();
			break;
		
		default:
			std::cout << "Incorrect input.\n";
			break;
	}

	wait( "Exit of program...\n" );
	
	return 0;
}


void forest()
{
	//Do all of your questions etc for the forest here.
	//Create functions for the other pages.
}

void city()
{
}

void prison()
{
}

void wait( char *message )
{
	std::cout << message;

	while( ! _kbhit() )
	{ /* do nothing */ }

	char c = _getch();
}
Last edited on
Still don't know if you know about classes, files, or vectors.

You need something that is more "data driven".

Here's a program I wrote for another thread. It is a soda machine menu. You can change the course of the whole program by changing line 13.

The program is mostly input validation, but this is a very important part of anything that has to do with data input.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <vector>
#include <string>

double getNum(void);
int getInt(void);
int getIntInRange(int low, int high);

int main(void)
{
  // This requires c++ 11
  std::vector<std::string> drinks = 
  { "Coke", "Pepsi", "Root Beer", "Sprite", "Fanta" };

  // If you do not have c++ 11, you can do
  //const char *d[] = 
  //{ "Coke", "Pepsi", "Root Beer", "Sprite", "Fanta" };
  //std::vector<std::string> drinks(sizeof(d) / sizeof(const char*));
  // for (unsigned int i = 0; i < drinks.size(); i++)
  //  drinks[i] = (std::string(d[i]));

  
  std::cout << "Welcome to the Soda Machine\n"
        << "Please make your selection\n";
  for (unsigned int i = 0; i < drinks.size(); i++)
    std::cout << i + 1 << ") " << drinks[i] << std::endl;
  std::cout << "\n: ";  
  
  int n = getIntInRange(1, drinks.size()) - 1;
  std::cout << "You picked: " << drinks[n] << '\n';
  return 0;
 }
 
double getNum(void){
  double n;
  while (!(std::cin >> n))
  {
    std::cin.clear();
    std::cin.ignore(80, '\n');
    std::cout << "Numbers only please, try again: ";
  }
  std::cin.ignore(80, '\n');
  return n;
}
int getInt(void){
  double n = getNum();
  while (n != static_cast<int>(n))
  {
    std::cout << "Integers only please, try again: ";
    n = getNum();  
  }
  return static_cast<int>(n);
}
int getIntInRange(int low, int high){
  int n = getInt();
  while (n < low || n > high)
  {
    std::cout << "Number must be in range (" <<low<<", "<<high <<")\n"
          << "Try again: ";
    n = getInt();  
  }
  return n;
}


The point is that there is no if/else, no switch. Just by inputing something valid, the program is able to output the correct thing.
Last edited on
Thanks for everything guys! (and girls if there are any)... I have used "program programmers" solution and it worked fine, i also tried the two above and they worked as well! i tried using switch but had a couple errors.. oh well.. i will get it soon enough. Thanks for all you have done for me! Code on!
Topic archived. No new replies allowed.
Pages: 12