Program to make Text adventure

Hello, I made a text application (command line tool) on xcode in C++. In the int main you can "program" the text adventure. I made a void called game which is where the game starts once the user decides to test out his "text adventure". The problem is that when I run it void game does not understand the strings because they are in the int main. How would I explain to the void game what the strings are (for example: The games name, the authors name etc). Thank you.
This is a small preview:
String gamename;
getline(cin,gamename);
//More code...
void game (){
cout << "Welcome to" << gamename; - Use of undeclared identifier
}
Last edited on
pass them as a parameter

1
2
3
4
5
6
7
8
9
10
11
12

void game( string name )
{
  cout << "Welcome to " << name;
}

int main()
{
  string nameofgame = "whatever";

  game( nameofgame );
}
Topic archived. No new replies allowed.