constructers and classes

How come when I try and display user.strength in the main() function, 0 is displayed? 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

#include <iostream>
#include <string>



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)
{
    std::string name = nam;
    int strength = str;
    int stamina = sta;
    int luck = luk;
    int stealth = stl;
    bool dead = ded; 
}


player user;

void intro()
{

    
    int tempstr;
    int tempsta;
    int templuk;
    int tempstl;
    std::string tempname;

    std::cout<<"enter your name:"<<std::endl;
    std::cin >> tempname;
    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 >> tempstr;
    std::cout<<"stamina:";
    std::cin >> tempsta;
    std::cout<<"luck:";
    std::cin >> templuk;
    std::cout<<"stealth:";
    std::cin >> tempstl;
    std::cout<<" "<<std::endl;
    
    user.make(tempname,tempstr, tempsta, templuk, tempstl, true);
}

int main (int argc, const char * argv[])
{
    intro();
    std::cout<<user.strength;
    return 0;
}
THe make function doesn't modify any of the member variables of the player class. You are defining new variables inside that function which you do nothing with so the whole function does nothing at all.
thanks so much, i've had this exact issue before, i don't know why i didn't catch it earlier.
Topic archived. No new replies allowed.