This is probabbly a really easy question but i cant figure it out.

How can i call other functions from my main for branching storyline purposes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int main ()
{
	cout <<"\tTest Game\n";
	char userName[100];
	cout <<"Please enter your username: ";
	cin >>userName;

cout <<"Hello, "<<userName<<"!\n\n";



cout <<"Please pick your past\n";

cout <<"1 - Poor\n";
cout <<"2 - Middle Class\n";
cout <<"3 - Rich\n";


So depending on the cin it would call a specific function.
Go check the tutorial on functions. It'll tell you have to define and call them.

Also, you should use std::strings instead of char arrays; strings are much easier to work with.
Not sure how to interpret your question.

From this:
How can i call other functions from my main for branching storyline purposes.

I would answer in a similar fashion to firedraco...however you also said:
So depending on the cin it would call a specific function.

So what exactly are you asking? Do you want to call a specific function based on the user's input? If that's the case and the options the user can pick are limited to only a few, you could use a set of decision if-else's based on the input string, and call a function corresponding to that string if it matches your check. Otherwise for a more robust and open design, you could use std::map for that. That is of course, if I understood what you wanted to do correctly...
You can use an if statement or a switch statement with a condition for the difficulty.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
cout <<"Please pick your past\n";

cout <<"1 - Poor\n";
cout <<"2 - Middle Class\n";
cout <<"3 - Rich\n";

int nDifficulty;
cin >> nDifficulty;

if (nDifficulty == 1)
{
     //code
}

if (nDifficulty == 2)
{
     //code
}

if (nDifficulty == 3)
{
     //code
}


read this: http://www.cplusplus.com/doc/tutorial/control/
Sorry im replying late

ENIGMAx i was asking about user input like you had guessed but momo answered me and sorry for this trash question. im seriously learning as i make this even the basics -_-. not the best way to learn but im gonna do it :)

EDIT: wow, i should really write the story first, this stuff is really elaborate.
Last edited on
Topic archived. No new replies allowed.