Help with my text game?

closed account (iNU7ko23)
Hi can anyone help me with some errors I'm getting in my program? Here is the code...
#include <iostream>
#include <string>
using namespace std;


bool intro(void)
string name = " ";


int _tmain(int argc, _TCHAR* argv[])
{

intro(void);
return 0;
}

bool intro(void)
{
using std::cout;
using std::cin;
cout << "Hi! What is your name? \n"
cin >> name;
cout << "Hello!"<< name;
cout << "We need you to defeat the evil dragon.\n";
cout << "To do this you will need to make a great journey.\n";
cout << "And then defeat the dragon at its source!\n";
cout << "Will you accept the challenge?\n";
cout << "1) Yes. \n";
cout << "2) No. \n\n";
int reply;
cin >> reply;
return !(reply == 1);
}

and the errors...




1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(8) : error C3646: 'string' : unknown override specifier
1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(8) : error C3646: 'name' : unknown override specifier
1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(8) : error C2072: 'intro' : initialization of a function
1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(8) : error C2440: 'initializing' : cannot convert from 'const char [2]' to 'bool (void)'
1> There are no conversions to function types, although there are conversions to references or pointers to functions
1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(14) : error C2144: syntax error : 'void' should be preceded by ')'
1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(14) : error C2059: syntax error : ')'
1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(23) : error C2146: syntax error : missing ';' before identifier 'cin'
1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(23) : error C2065: 'name' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\my new quest\my new quest\my new quest.cpp(24) : error C2065: 'name' : undeclared identifier
1>Build log was saved at "file://c:\Users\User\Documents\Visual Studio 2008\Projects\MY NEW QUEST\MY NEW QUEST\Debug\BuildLog.htm"

If you could tell me what I'm getting wrong thanks!
Eh.... I just fixed it up for you:


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
#include <iostream>
#include <string>
using namespace std;


bool intro();
string name = " ";


int main( )
{

intro();
return 0;
}

bool intro()
{
using std::cout;
using std::cin;
cout << "Hi! What is your name? \n";
cin >> name;
cout << "Hello!"<< name;
cout << "We need you to defeat the evil dragon.\n";
cout << "To do this you will need to make a great journey.\n";
cout << "And then defeat the dragon at its source!\n";
cout << "Will you accept the challenge?\n";
cout << "1) Yes. \n";
cout << "2) No. \n\n";
int reply;
cin >> reply;
return !(reply == 1);
}
Also.... I don't see why your using a function. Thats really unnecessary. Just copy-and-paste the code from the intro function you wrote and put it in your main function.

EDIT: One last and final word:

Please use code tags! ([code])
Last edited on
Code Assassin wrote:
I don't see why your using a function. Thats really unnecessary.

Splitting code into different functions can be a good way to structure code.
closed account (zb0S216C)
Duplicate: http://www.cplusplus.com/forum/beginner/60318/

Wazzak
Topic archived. No new replies allowed.