Open on file fro another

Hi not sure if my title is correct but what I want to do is take input from a user then open a new file

Main


#include <iostream>
using namespace std;



int main()

{
int title;
loop:

cout << "Welcome to Text world" << endl;
cout << "Press 1 to start or 2 for help ";

cin >> title;

if
(title == 1)
cout << "loading..." << endl;

else if
(title == 2)
cout << "Help...." << endl;

else
{
cout << "Invalid selection, please try again...." << endl;
goto loop;
}




return 0;
}

If the user presses 2 I want them to go to a help.cpp file in the same folder

help

// Help

#include <iostream>
using namespace std;



int help()

{

cout << "Welcome to help, this screen shows the basic conceps of the game..." endl;

}

Hope you know what i mean
Like this ?
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
#include <iostream>
using namespace std;



int main()

{
int title;
loop:

cout << "Welcome to Text world" << endl;
cout << "Press 1 to start or 2 for help \n";

cin >> title;

if
(title == 1)
cout << "loading..." << endl;

else if
(title == 2) {
cout << "Help...." << endl;
help();
}
else
{
cout << "Invalid selection, please try again...." << endl;
goto loop;
}




return 0;
}


and help function signature is incorrect, this will NOT compile:
1
2
3
4
5
6
7
int help()

{

cout << "Welcome to help, this screen shows the basic conceps of the game..." endl;

}


Either change it or return an int:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int help()

{

cout << "Welcome to help, this screen shows the basic conceps of the game..." << endl;
return 0;
}

// or like this:
void help()

{

cout << "Welcome to help, this screen shows the basic conceps of the game..." << endl;

}
Last edited on
Topic archived. No new replies allowed.