32767??? help!

Im, making a little text-based game, but whenever I call the dislay() function on any of my weapons, the console will return the max int #. Run it in your own IDE please and tell me what I'm doing wrong, thanks in advance. Its some long code, but the main problem is in the weapons() function.
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

// GLOBAL VARIABLES
string charname;

//NAV CLASS
class nav
{
public:
    int navatk;
    int navdef;
    int navspd;
    int navluk;
    int navhpo;
    int navepo;
    
//CLASS MEMBER FUNCTIONS
    void INIT(int navattack, int navdefense, int navspeed, int navhp, int navluck, int navenergy);
    void display();
};
//NAV MEMBER FUNCTION DEFINITIONS
void nav::INIT(int navattack, int navdefense, int navspeed, int navhp, int navluck, int navenergy)
{
    navatk = navattack;
    navdef = navdefense;
    navspd = navspeed;
    navhpo = navhp;
    navluk = navluck;
    navepo = navenergy;
    
}
void nav::display()
{
    cout<<"attack: "<< navatk <<endl;
    cout<<"defense: "<< navdef <<endl;
    cout<<"speed: "<< navspd <<endl;
    cout<<"health points: "<< navhpo <<endl;
    cout<<"luck: "<< navluk <<endl;
    cout<<"energy points: "<< navepo <<endl;

}
//BUG CLASS
class bug
{
public:
    int bugatk;
    int bugdef;
    int bugluk;
    int bugspd;
    int bughpo;
    int bugepo;
    
//CLASS MEMBER FUNCTIONS
    void INIT(int bugattack, int bugdefense, int bugspeed, int bughp, int bugluck, int bugenergy);
    void display();
};
//BUG MEMBER FUNCTION DEFINITIONS

void bug::INIT(int bugattack, int bugdefense, int bugspeed, int bughp, int bugluck, int bugenergy)
{
    bugatk = bugattack;
    bugdef = bugdefense;
    bugspd = bugspeed;
    bughpo = bughp;
    bugluk = bugluck;
    bugepo = bugenergy;
    
}

void bug::display()
{
    cout<<"attack: "<< bugatk <<endl;
    cout<<"defense: "<< bugdef <<endl;
    cout<<"speed: "<< bugspd <<endl;
    cout<<"health points: "<< bughpo <<endl;
    cout<<"luck: "<< bugluk <<endl;
    cout<<"energy points: "<< bugepo <<endl;    
}

//WEAPON CLASS
class userweap
{
public:    
    int id;
    int power;
    int cost;
    string descrip;

//CLASS MEMBER FUNCTIONS
    void INIT(int id, int weappower, int weapcost);
    void display();
    string equip();
};
//CLASS MEMEBER FUNCTION DEFINITIONS

void userweap::INIT(int id, int weappower, int weapcost)
{
    weappower = power;
    weapcost = cost;
}
void userweap::display()
{
    cout<<"power: " << power <<endl;
    
}
string userweap::equip()
{
    string equipped;
    equipped = id;
    return equipped;
}
//GLOBAL HELPER FUNCTIONS
void intro();
string choice(nav & user);
void btutorial();
string allgood();
void checkstats(bug & simbug, nav & user);
void simbugmake(bug & simbug);
void regcannonmake(userweap & regcannonweap);
void beamswordmake(userweap & beamsword);
void laserbowmake(userweap & laserbow);
void flyingfistmake(userweap & flyingfist);
void razordiscmake(userweap & razordisc);
void blockpunchmake(userweap & blockpunch);
void flaremake(userweap & flare);
void wavemake(userweap & wave);
void whipmake(userweap & whip);
void mindshotmake(userweap & mindshot);
void weapons(userweap & regcannon);

//MAIN FUNCTION
int main(){
    nav dummynav;
    userweap dummyweap;
    intro();
    while( choice(dummynav) == "no") cout<< "let me show you them again" << endl;
    btutorial();
    while( allgood() == "no");
    sleep(1);
    weapons(dummyweap); 
    return 0;
}

void intro()
{
    cout<<"what's your name again?"<<endl;
    cin>>charname;
    cout<<"pick a nav"<< endl;
}

string choice(nav & user)
{
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"bladenav: a well balanced navigator that can wield a multitude of de-bugging weapons"<<endl;
    cout<<"arrownav: a speed-oriented navigator that can attack stealthily from far range"<<endl;
    cout<<"fistsnav: an attack-heavy navigator with low speed but with a variety of high-power weapons"<<endl;
    cout<<"shellnav: an extremely high defense navigator with low speed and attack "<<endl;
    cout<<"golemnav: a high attack, high defense navigator with low speed, and a narrow range of attacks "<< endl;
    cout<<"flamenav: a navigator with flame-based attacks with relatively large luck"<<endl;
    cout<<"aqueonav: a navigator with aqua-based attacks with relatively large luck"<<endl;
    cout<<"plantnav: a navigator with plant-based attacks with relatively large luck"<<endl;
    cout<<"psychnav: a high hit points navigator with indirect attacking abilities"<<endl;
    cout<<"chicknav: a navigator with terrible stats all around and no redeeming qualities whatsoever except for it's 100% luck stat."<<endl;
    sleep(3);
    cout<<"you may choose one and only one to control. pick wisely"<<endl;
    string navchoice;
    cin>> navchoice;
    if (navchoice == "bladenav") user.INIT(50, 50, 50, 100, 10, 40);
    else if (navchoice =="arrownav") user.INIT(55, 30, 65, 100, 10, 40);
    else if (navchoice =="fistsnav") user.INIT(80, 55, 10, 115, 10, 30);
    else if (navchoice =="shellnav") user.INIT(25, 80, 25, 120, 10, 40);
    else if (navchoice =="golemnav") user.INIT(70, 70, 10, 100, 10, 40);
    else if (navchoice =="flamenav") user.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="aqueonav") user.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="plantnav") user.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="psychnav") user.INIT(20, 30, 30, 150, 10, 50);
    else if (navchoice =="chicknav") user.INIT(20, 20, 20, 100, 100, 40);
    sleep(1);
    user.display();
    sleep(1);
    cout<<"is this you're final selection, "<< charname <<"?"<<endl;
    string yesno;
    cin >> yesno;
    return yesno;
}

void btutorial()
{
    userweap dummyweap;
    regcannonmake(dummyweap);
    beamswordmake(dummyweap);
    laserbowmake(dummyweap);
    flyingfistmake(dummyweap);
    razordiscmake(dummyweap);
    blockpunchmake(dummyweap);
    flaremake(dummyweap);
    wavemake(dummyweap);
    whipmake(dummyweap);
    mindshotmake(dummyweap);    
    cout<<"now that you've chosen your navigator, you should probably learn how to use it."<<endl;
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"when you find an enemy 'bug', battle mode is initiated."<<endl;
    sleep(1);
    cout<<" ______________________________________________________"<<endl;
    cout<<"|ATTACK| WEAPONS | ITEMS | FLEE | CHECK STATS | DEFEND |"<<endl;
    cout<<"|______|_________|_______|______|_____________|________|"<<endl;
    sleep(1);
    cout<<"(too many characters)."<<endl;
    sleep(10);
    cout<<"then, after your turn is over, your oppenent will either attack or defend."<< endl;
}

string allgood()
{
    sleep(5);
    cout<< "all good?" <<endl;
    string yesno;
    cin >> yesno;
    return yesno;
}

//WEAPON CREATION
void regcannonmake(userweap & regcannon)
{
    regcannon.INIT(1,5,0);
}
void beamswordmake(userweap & beamsword)
{
    beamsword.INIT(2,7,1);
}
void laserbowmake(userweap & laserbow)
{
    laserbow.INIT(3,6,1);
}
void flyingfistmake(userweap & flyingfist)
{
    flyingfist.INIT(4,8,1);
}
void razordiscmake(userweap & razordisc)
{
    razordisc.INIT(5,4,1);
}
void blockpunchmake(userweap & blockpunch)
{
    blockpunch.INIT(6,5,1);
}
void flaremake(userweap & flare)
{
    flare.INIT(7,5,1);
}
void wavemake(userweap & wave)
{
    wave.INIT(8,5,1);
}
void whipmake(userweap & whip)
{
    whip.INIT(9,5,1);
}
void mindshotmake(userweap & mindshot)
{
    mindshot.INIT(10,7,1);
}
//CHECKSTATS
void checkstats(bug & simbug, nav & user)
{
    cout<<"your stats:"<< endl;
    user.display();
    cout<<""<< endl;
    cout<<"bug's stats:"<< endl;
    simbug.display();
}
void weapons(userweap & regcannon)
{
    
    sleep(1);
    cout<<"weapons:"<<endl;
    cout<<"regcannon"<<endl;
    sleep(1);
    cout<< "pick one" <<endl;
    string weapchoice;
    cin >> weapchoice;
    if (weapchoice == "regcannon")
    {
        regcannon.display();
        regcannon.equip();
        while( allgood() == "no");
        cout<< charname << " equipped the regcannon" <<endl; 
    }
    
}
void flee();
void flee()
{
     
}
void defend(nav & user);
void defend(nav & user)
{
      
}
void items();
void items()
{
    
}
bool battle(nav & user);
bool battle(nav & user)
{
    bug simbug;
    simbug.INIT(10,10,10,10,10,10);
    cout<<simbug.bugatk<<endl;
    
    return true;
}
closed account (D80DSL3A)
The assignments are reversed in this function:
1
2
3
4
5
void userweap::INIT(int id, int weappower, int weapcost)
{
    weappower = power;
    weapcost = cost;
}

It should be:
1
2
3
4
5
void userweap::INIT(int id, int weappower, int weapcost)
{
    power = weappower;
    cost = weapcost;
}

You are leaving id and descrip uninitialized. id is passed as a parameter, but it isn't used.
thanks, i havent gotten to use id or descrip yet.

Topic archived. No new replies allowed.