class members and assignments

Hi, im currently making a oregon trail rip-off, but when i try to assign the stats to the characters using the player::make() class-function, only some work, and others don't! i'd really appreciate it if someone could look through my code and debug it? I've been debugging for an hour and i'm about to throw this code out the window... help!
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//
//  main.cpp
//  trail
//
//  Copyright 2014 jesse smith. All rights reserved.
//

#include <iostream>
#include <string>
#include <time.h>


class player
{
public:  
    std::string name;
    int strength;
    int stamina;
    int luck;
    int stealth;
    bool dead;
    
    void make(std::string, int, int, int, int, bool);

};

void player::make(std::string nam, int str, int sta, int luk, int stl, bool ded)
{
    name = nam;
    strength = str;
    stamina = sta;
    luck = luk;
    stealth = stl;
    dead = ded; 
}


player user;
player assist;
player team1;
player team2;
player team3;


static void team_build(std::string r, std::string z)
{
    int o = 1;
    std::string t;
    std::string e;
    int en;
    std::string temp_name;
    int temp_str;
    int temp_sta;
    int temp_luk;
    int temp_stl;
    bool q = 0;
    
    if(r == "a")t = "assistant's";
    if(r == "t")t = "team member's";  
    
    if(r == "a")e = "twenty five";
    if(r == "t")e = "twenty";
    
    if(r == "a")en = 25;
    if(r == "t")en = 20;
    
    do
    {
        
        std::cout<<"allocate "+ e +" skill points to these four stats. these will serve as your" + t + " stats."<<std::endl;
        std::cout<<"strength, stamina, luck, stealth"<<std::endl;
        std::cout<<"strength:";
        std::cin >> temp_str;
        std::cout<<"stamina:";
        std::cin >> temp_sta;
        std::cout<<"luck:";
        std::cin >> temp_luk;
        std::cout<<"stealth:";
        std::cin >> temp_stl;
        std::cout<<" "<<std::endl;
        
        if (temp_str + temp_sta + temp_luk + temp_stl > en)
        {
            std::cout<<"you've allocated over "+ e +" skill points"<<std::endl;
            q = 1;
        }
        
        else
        {
            q = 0;    
        }
        if(r == "a")assist.make(z,temp_str, temp_sta, temp_luk, temp_stl, true);
        if(r == "t" && o == 1)team1.make(z,temp_str, temp_sta, temp_luk, temp_stl, true);
        if(r == "t" && o == 2)team2.make(z,temp_str, temp_sta, temp_luk, temp_stl, true);
        if(r == "t" && o == 3)team3.make(z,temp_str, temp_sta, temp_luk, temp_stl, true);
        
    }while(q == 1);
    
    o++;
}

static void teamssemble()
{
    std::string temp_name;
    
    std::cout<<"you won't be traveling alone!"<<std::endl;
    std::cout<<"you will have a team of four other members to accompany you on your journey through the yukon mountains."<<std::endl;
    std::cout<<"first, what is the name of your first team member:";
    std::cin >> temp_name;
    std::cout<<"this team member will serve as your personal assistant and second in command on your journey."<<std::endl;
    team_build("a",temp_name);
    std::cout<<"next, what is the name of your second team member:";
    std::cin >> temp_name;
    team_build("t",temp_name);
    std::cout<<"next, what is the name of your third team member:";
    std::cin >> temp_name;
    team_build("t",temp_name);
    std::cout<<"next, what is the name of your fourth team member:";
    std::cin >> temp_name;
    team_build("t",temp_name);
}


static void user_build()
{
    std::string temp_name;
    int temp_str;
    int temp_sta;
    int temp_luk;
    int temp_stl;
    bool q = 0;
    
    std::cout<<"enter your name:"<<std::endl;
    std::cin >> temp_name;
    
    do
    {
        
        std::cout<<"allocate thirty skill points to these four stats. these will serve as your main player's stats."<<std::endl;
        std::cout<<"strength, stamina, luck, stealth"<<std::endl;
        std::cout<<"strength:";
        std::cin >> temp_str;
        std::cout<<"stamina:";
        std::cin >> temp_sta;
        std::cout<<"luck:";
        std::cin >> temp_luk;
        std::cout<<"stealth:";
        std::cin >> temp_stl;
        std::cout<<" "<<std::endl;
    
        if (temp_str + temp_sta + temp_luk + temp_stl > 30)
        {
            std::cout<<"you've allocated over thirty skill points"<<std::endl;
            q = 1;
        }
        
        else
        {
            q = 0;    
        }
        
        user.make(temp_name,temp_str, temp_sta, temp_luk, temp_stl, true);
    
    }while(q == 1);
}

static bool pathbegin()
{
    int rand4 = rand() % 4 + 1;
    std::string rand_name;
    
    std::cout<<user.name + ", " + assist.name + ", " + team1.name + ", " + team2.name + ", and " + team3.name + "gaze up at the mountains ahead of them. the sparkling moonlight shines on their faces."<<std::endl;
    std::cout<<user.name + " sighs in awe of the trail ahead."<<std::endl;
    sleep(1);
    switch (rand4)
    {
        case 1:
            rand_name = assist.name;
            break;
        case 2:
            rand_name = team1.name;
            break;
        case 3:
            rand_name = team2.name;
            break;
        case 4:
            rand_name = team3.name;
            break;
    }
    std::cout<< rand_name + " trips on a rock and falls face-first into the snow"<<std::endl;
    return true;
}

int main (int argc, const char * argv[])
{
    user_build();
    teamssemble();
    pathbegin();
    std::cout<<assist.strength << team1.strength << " " << team2.strength << " " << team3.strength;
    return 0;
}

Last edited on
In team_build(), o is always assigned to 1 at the beginning of the function. The best way for you probably is to pass in the value of o as a parameter., so your calls in teamassemble() look like:
team_build("t", temp_name, 1);.

Alternatively, you could consider using an enum to denote which team member it is that you're assigning.
thanks so much!

-ascii14
Topic archived. No new replies allowed.