Text Based Game Help

In the main it asks you for your name, then within a class and a function within the class it uses the variable char name which is your name. How do i get this to work, (dont worry about other errors im still working on it)

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
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <string>

using namespace std;


class storyline1{
public:

int Getaway(){

}

int HelpOldMan(){
cout << "You walk up to the old man and you see blood everywhere. \n His eyes are close and you think hes dead, but before he dies he says \n Prince" << char name;
}

int Banditloot(){
cout << "You pick up 10 gold off one of the bandits bodies." << endl;
cout << "1. Go back and see if the old man is ok. /n 2. Get away from the area before anyone comes.";
cin << y;

if(y==1){
    HelpOldMan();

}else
if(y==2){
    Getaway();

}



}

int oldman1(){
cout << " \n \n \n \n \n \n \n The man grabs your hand and starts running down the dusty road. \n Suddenly an arrow comes out from the forest and strikes the man in the heart. \n ";
cout << " \n \n \n 3 Men with bows are running towards you, you grab the bow off the mans body." << endl;
cout << " \n \n You draw the bow back to your cheek and fire your first arrow. \n \n You hit him right in the chest. \n You shoot another arrow at the second man and hit him in the leg. \n \n The third man shoots an arrow at your head and slightly misses. \n You draw the bow back to your cheek one last time and hit him right in the eye. \n Blood gushes everywhere and the man shot in the leg limps away.";
cout << " \n Press enter to continue." << endl;
cin.ignore();
cin.get();
cout << "1. Go search the dead bandit's bodies for loot. \n 2. Escape the area while you can! \n 3. Check to see if the mysterious man is alive." << endl;
cin >> x;
if(x==1)
{


}else if(x==2){

}else if(x==3){
int HelpOldMan();

}
}
int Searchbodies(){
};


private:
int x;
int gold;
int y;

};

int main()
{
    cout << " Welcome to Tyler Tongen's first text based game, the decisions you make \n in this game will determine if you survive or not \n \n Goodluck \n." << endl;
    cout << "What is your name?";
    char name;
    cin >> char name;
    cout << " You Wake up on the side of a dusty road \n \n An Old man with a hood and a quiver full of arrows walks up to you \n \n Wake up! There is no time to explain, but you need to come with me!";
    cout << " \n 1. Go with the man. \n 2. Run away." << endl;
    storyline1 to1;
    int x;
    cin >> x;
        if( x == 1 ){
            to1.oldman1();
        }
        return 0;
};
Well first off, a char is just one character. I'll assume that you want to have a name with more than one letter, so you would use either a string or a char*
Make name a member variable for storyline1. When you ask the name, then call a setter to store the name into the class instance, or have a constructor of storyline1 that takes name as an argument.

line 72: You don't want char here.

Line 71: You don't want a single character name. name should be a std::string.

Topic archived. No new replies allowed.