What did i do wrong? (Functions)

Ok so here is my code:

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

void Store(int,int,int);
void func2();

int main()
{
    string Mchoice;

    cout << "Hello which place would you like to go?" << endl;
    cin >> Mchoice;

    while(Mchoice != "Quit" || Mchoice == "quit"){

        if(Mchoice == "Store" || Mchoice == "store"){
            Store(int health, int level, int money);
        }
    }

    cin.get();
    return 0;
}

void Store(int health, int level, int money)
{
    string choice;

    cout << "what you like to buy?" << endl;
    cout << "\n";
    cout << "A - clothes" << endl;
    cout << "     " << "$10" << endl;
    cout << "B - " << endl;
    cin >> choice;

    if(choice == "A"){
        money -=10;
        cout << "Current Money: $" << money;
    }
}

void func2()
{

int health = 100;
    int level = 1;
    int money = 150;
    Store(health, level, money);

}


func2 needs to access Store to get the current money and to subtract $10 from the players overall money, now this worked perfect when the contents of func2 were all in main(), however when i put them in func 2 they dont want to work now, here is my compiler error:

C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: expected primary-expression before 'int'|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: expected primary-expression before 'int'|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: expected primary-expression before 'int'|
||=== Build finished: 3 errors, 0 warnings ===|

What did i do wrong?
On line 18, you are calling Store() incorrectly. It should be like line 49.
Now i get this error:

C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: 'health' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: 'level' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: 'money' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings ===|
What do i do? i've been stuck onb this for 6 days and my patience is running thin so PLEASE help.
closed account (10oTURfi)
You might want to pass health, level and money to func2.
void func2(int, int, int); // Line 6
....
void func2(int health, int level, int money) // line 43

Also line 18 is weird:
Store(health, level, money);//This should do for line 18

And you while loop isnt gonna work as intended.
while(Mchoice != "Quit" || Mchoice != "quit")//This should do
Last edited on
GRRRRRR, now it gives me this:

C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: 'health' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: 'level' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|18|error: 'money' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp||In function 'void func2(int, int, int)':|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|46|error: declaration of 'int health' shadows a parameter|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|47|error: declaration of 'int level' shadows a parameter|
C:\Users\Chay Hawk\Desktop\C++ Projects\C++\main.cpp|48|error: declaration of 'int money' shadows a parameter|
||=== Build finished: 6 errors, 0 warnings ===|
you should learn about basics of c++. probably, you just write it without declare the variables needed first... and that means that, you should not declare the same variable in func2 again...
i know how to do it i just didnt think it needed to be in there since i though it was getting it from func2, now here is my new code and i have some problems in 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
#include <iostream>
#include <string>
using namespace std;

void Store(int,int,int);
void func2();

int main()
{
    string Mchoice;

    int health;
    int level;
    int money;

    cout << "Hello which place would you like to go?" << endl;
    cin >> Mchoice;

    while(Mchoice != "Quit" || Mchoice == "quit"){

        if(Mchoice == "Store" || Mchoice == "store"){
            Store(health, level, money);
        }
    }

    cin.get();
    return 0;
}

void Store(int health, int level, int money)
{
    string choice;

    cout << "what you like to buy?" << endl;
    cout << "\n";
    cout << "A - clothes" << endl;
    cout << "     " << "$10" << endl;
    cout << "B - " << endl;
    cin >> choice;

    if(choice == "A"){
        money -=10;
        cout << "Current Money: $" << money;
    }
}

void func2()
{

    int health = 100;
    int level = 1;
    int money = 150;
    Store(health, level, money);

}


this works now, BUT here is what it looks like executed

Hello which place would you like to go?

(i type in Store)

A - clothes
$10
B -
(I type A)

Then here is the errors:

Current Money: $4273852what would you like to buy?

A - clothes
$10
B -


The total money should be $140 and what would you like to buy?

A - clothes
$10
B -

Shouldnt be there, so what the hell did i do wrong this time? I want some goddam answers this is starting to piss me off. 6 days of this is wearing on my nerves.
You are creating an int named money on line 14. You do not set it to any value, so it will have some random value in it.

It does not magically know what value you want it to start with. You must set it to some value. For example, like this:

int money = 150;

You are trying to do this in func2. However, you never called func2 so that code never gets run so the value of money is never set.
Last edited on
Ok i fixed the other crap but it still gives me $4273852, why is that?
Ok i got it, i didnt even need func2 or anything in it, but there is still one little annoying issue, i have to enter store twice to go to the store, so is there a way to change that to only the first time?
Yes there is. We'll need to see your new code to tell you how.
I actually started working on my other program which is the same thing as above, above was just a test so i could get my game working, however i do have a major problem in it. Ok so i have the code all working and when i buy something its supposed to subtract from the players money which it doesnt when i go to stats, but it does subtract if i show the money in that function: here is my code:

sorry its massive but the main parts you need to look at are int main, Stats and FeedTextPet

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
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

void help();
void RenameTextPet();
void Stats(int,int,int);
void Arena();
void FeedTextPet(int);
void OtherInfo(int,int,int);

//Main Program
int main()
{
    string death = "Your TextPet has died";
    string choice;

    int health = 100;
    int money = 20;
    int level = 1;

    while(choice !="quit"){
        cin >> choice;

            if(choice == "Help" || choice == "help"){
                help();
                }

                    if(choice == "Rename" || choice == "rename"){
                    RenameTextPet();
                    }

                        if(choice == "Stats" || choice == "stats"){
                        Stats(health, money, level);
                        }

                            if(choice == "Feed" || choice == "feed"){
                            FeedTextPet(money);
                            }

                                if(choice == "Arena" || choice == "arena"){
                                Arena();
                                }
    }

    cin.get();
    return 0;
}


//Help Function
void help()
{
    string choice;

            cout << "\n";
            cout << "HELP DOCUMENTATION" << endl;
            cout << "\n";
            cout << "Below is a list of catagories, please type in the letter next to the catagorie to see more info on that subject" << endl;
            cout << "\n";

            cout << "A - Keywords" << endl;
            cout << "B - Pets List" << endl;
            cin >> choice;
            cout << "\n";

            if(choice == "A" || choice == "a"){
                cout << "KEYWORDS LIST" << endl;
                cout << "\n";
                cout << "Quit - Exits from the game" << endl;
                cout << "Feed - Feeds your TextPet" << endl;
                cout << "Rename - Allows you to re-name your text pet" << endl;
                cout << "Stats - Shows your stats like pet name, money, pet health etc" << endl;
                cout << "School - You can go to school and learn stuff" << endl;
                cout << "\n";
            }

            if(choice == "B" || choice == "b"){
                cout << "TextCat" << endl;
                cout << "TextDog" << endl;
                cout << "TextGuineaPig" << endl;
                cout << "TextHampster" << endl;
            }
}


//Choose TextPet
void choosepet()
{
    string TextPetChoose;
    string TextPet;

    cout << "Ok now please choose your TextPet" << endl;
    cout<< "Only type the number next to the pet you wish to choose" << endl;
    cout << "\n";
    cout << "1 - TextDog" << endl;
    cout << "2 - TextCat" << endl;
    cout << "3 - TextHampster" << endl;
    cout << "4 - TextGuineaPig" << endl;
    cout << "\n";
    getline(cin, TextPetChoose);
    cout << "\n";
}


//Here you can rename your pet
void RenameTextPet()
{
    string rename;

    cout << "What would you like to re-name your pet?" << endl;
    cout << "\n";
    getline(cin, rename);
    cout <<"\n";
}

//View Statistics
void Stats(int health, int money, int level)
{
    cout << "\n";
    cout << "Pet Health: " << health << endl;
    cout << "\n";
    cout << "Money: "<< "$" << money << endl;
    cout << "\n";
    cout << "Level: " << level << endl;
}


//School for your TextPet
void School()
{
    string SchoolChoice;

    cout << "Welcome to school! here you can make your TextPet smarter and earn achievements and skill points." << endl;
    cout << "\n";
    cout << "Please choose which classes you would like to take:" << endl;
    cout << "\n";
    cin >> SchoolChoice;
    cout << "\n";

    cout << "A - History" << endl;
    cout << "B - Math" << endl;
    cout << "C - Science" << endl;
    cout << "D - Biology" << endl;

    if(SchoolChoice == ""){

    }

}


//Feed TextPet
void FeedTextPet(int money)
{
    string FoodChoice;

    cout << "What would you like to feed your TextPet?" << endl;
    cout << "\n";
    cout << "A - TextPet Low Grade Food" << endl;
    cout << "     " << "Cost: $2" << endl;
    cout << "     " << "     " << "Health Restored: 3 points" << endl;
    cout << "\n";
    cout << "B - TextPet Medium Grade Food" << endl;
    cout << "     " << "Cost: $5" << endl;
    cout << "     " << "     " << "Health Restored: 6 points" << endl;
    cout << "\n";
    cout << "C - TextPet High Grade Food" << endl;
    cout << "     " << "Cost: $10" << endl;
    cout << "     " << "     " << "Health Restored: 14 points" << endl;
    cin >> FoodChoice;

    if(FoodChoice == "A" || FoodChoice == "a"){
        money -= 2;
        cout << "You bought 'TextPet Low Grade Food'" << endl;
    }
}


//This will start in the beginning only, if the person has played before it will not show again.
void beginning()
{
    string TextPetName;
    string PlayerName;

    cout << "Welcome to the world of TextPet" << endl;
    cout << "TextPet is a interactive text pet that you can play with!" << endl;
    cout << "If you need help, just type in help at anytime" << endl;
    cout << "Its suggested you visit the help corner if this is your first time playing" << endl;
    cout << "\n";
    cout << "Press Enter to begin" << endl;
    cin.get();

    //Enter your name
    cout << "Ok lets start by entering your name" << endl;
    cout << "\n";
    getline(cin, PlayerName);
    cout << "\n";

    //Name your TextPet
    cout << "what do you want to name your new TextPet?" << endl;
    getline(cin, TextPetName);
    cout << "\n;";
}


//The player can level up their TextPet
void LevelUp()
{


}


//These are achievements that the player can earn
void Achievements()
{



}


//This is the Arena where your TextPet can fight in.
void Arena()
{
    string ArenaChoice;

    cout << "Welcome to the arena which fight would you like to enter your pet in?" << endl;
    cout << "\n";
    cout << "A - Low Level" << endl;
    cout << "     " << "Requirements: Level 1-15" << endl;
    cout << "\n";
    cout << "B - " << endl;
    cout << "     " << "Requirements: Level 15-30" << endl;
    cout << "\n";
    cout << "C - " << endl;
    cout << "     " << "Requirements: Level 30-" << endl;
    cin >> ArenaChoice;

    if(ArenaChoice == "A" || ArenaChoice == "a"){
        cout << "test" << endl;
    }

        if(ArenaChoice == "B" || ArenaChoice == "b"){
            cout << "test" << endl;
        }
}
When you pass the variable money to your function feedTextPet, a copy of the variable money is made and passed to the function. Everything the function does, it does to that copy. When the function ends, that copy is destroyed. When the execution goes back to where the function was called and carries on, the original variable has not been changed.

If you want to change the original variable, you must either pass a pointer the the variable, pass the variable by reference, or return a value from the function and change the original variable yourself using information returned from the function.

I suggest you pass the variable by reference.
Here is your program. Pay attention to your functions "int, int, int" what?!
Here fixed:


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

void Store(int health, int level, int money);
void func2();

int main()
{
    string Mchoice;

    cout << "Hello which place would you like to go?" << endl;
    cin >> Mchoice;

    while(Mchoice != "Quit" || Mchoice == "quit"){

        if(Mchoice == "Store" || Mchoice == "store"){
            func2();
        }
    }

    cin.get();
    return 0;
}

void Store(int health, int level, int money)
{
    string choice;

    cout << "what you like to buy?" << endl;
    cout << "\n";
    cout << "A - clothes" << endl;
    cout << "     " << "$10" << endl;
    cout << "B - " << endl;
    cin >> choice;

    if(choice == "A"){
        money -=10;
        cout << "Current Money: $" << money;
    }
}

void func2()
{

int health = 100;
    int level = 1;
    int money = 150;
    Store(health, level, money);

}
Last edited on
I changed the int values to money health level and it still didnt work, i think im going to try passing it by refrence like Moschops said.
-->>
Last edited on
Someone told me that the Return statement would be better to use but how do i do that? what i mean is where do i even begin and what would it look like?

Code:

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
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

void help();
void RenameTextPet();
void Stats(int health, int money, int level);
void Arena();
void FeedTextPet(int);
void OtherInfo(int,int,int);
void PassByReferenceStats(int health, int money, int level);

//Main Program
int main()
{
    string death = "Your TextPet has died";
    string choice;

    int health = 100;
    int money = 20;
    int level = 1;

    while(choice !="quit"){
        cin >> choice;

            if(choice == "Help" || choice == "help"){
                help();
                }

                    if(choice == "Rename" || choice == "rename"){
                    RenameTextPet();
                    }

                        if(choice == "Stats" || choice == "stats"){
                        Stats(health, money, level);
                        }

                            if(choice == "Feed" || choice == "feed"){
                            FeedTextPet(money);
                            }

                                if(choice == "Arena" || choice == "arena"){
                                Arena();
                                }
    }

    cin.get();
    return 0;
}

//Help Function
void help()
{
    string choice;

            cout << "\n";
            cout << "HELP DOCUMENTATION" << endl;
            cout << "\n";
            cout << "Below is a list of catagories, please type in the letter next to the catagorie to see more info on that subject" << endl;
            cout << "\n";

            cout << "A - Keywords" << endl;
            cout << "B - Pets List" << endl;
            cin >> choice;
            cout << "\n";

            if(choice == "A" || choice == "a"){
                cout << "KEYWORDS LIST" << endl;
                cout << "\n";
                cout << "Quit - Exits from the game" << endl;
                cout << "Feed - Feeds your TextPet" << endl;
                cout << "Rename - Allows you to re-name your text pet" << endl;
                cout << "Stats - Shows your stats like pet name, money, pet health etc" << endl;
                cout << "School - You can go to school and learn stuff" << endl;
                cout << "\n";
            }

            if(choice == "B" || choice == "b"){
                cout << "TextCat" << endl;
                cout << "TextDog" << endl;
                cout << "TextGuineaPig" << endl;
                cout << "TextHampster" << endl;
            }
}


//Choose TextPet
void choosepet()
{
    string TextPetChoose;
    string TextPet;

    cout << "Ok now please choose your TextPet" << endl;
    cout<< "Only type the number next to the pet you wish to choose" << endl;
    cout << "\n";
    cout << "1 - TextDog" << endl;
    cout << "2 - TextCat" << endl;
    cout << "3 - TextHampster" << endl;
    cout << "4 - TextGuineaPig" << endl;
    cout << "\n";
    getline(cin, TextPetChoose);
    cout << "\n";
}


//Here you can rename your pet
void RenameTextPet()
{
    string rename;

    cout << "What would you like to re-name your pet?" << endl;
    getline(cin, rename);
    cout <<"\n";
}

//View Statistics
void Stats(int health, int money, int level)
{
    cout << "\n";
    cout << "Pet Health: " << health << endl;
    cout << "\n";
    cout << "Money: "<< "$" << money << endl;
    cout << "\n";
    cout << "Level: " << level << endl;
}


//School for your TextPet
void School()
{
    string SchoolChoice;

    cout << "Welcome to pet school! here you can make your TextPet smarter and earn achievements and skill points." << endl;
    cout << "\n";
    cout << "Please choose which classes you would like to take:" << endl;
    cout << "\n";
    cin >> SchoolChoice;
    cout << "\n";

    cout << "A - History" << endl;
    cout << "B - Math" << endl;
    cout << "C - Science" << endl;
    cout << "D - Biology" << endl;

    if(SchoolChoice == ""){

    }

}


//Feed TextPet
void FeedTextPet(int money)
{
    string FoodChoice;



    cout << "What would you like to feed your TextPet?" << endl;
    cout << "\n";
    cout << "A - TextPet Low Grade Food" << endl;
    cout << "     " << "Cost: $2" << endl;
    cout << "     " << "     " << "Health Restored: 3 points" << endl;
    cout << "\n";
    cout << "B - TextPet Medium Grade Food" << endl;
    cout << "     " << "Cost: $5" << endl;
    cout << "     " << "     " << "Health Restored: 6 points" << endl;
    cout << "\n";
    cout << "C - TextPet High Grade Food" << endl;
    cout << "     " << "Cost: $10" << endl;
    cout << "     " << "     " << "Health Restored: 14 points" << endl;
    cin >> FoodChoice;

    if(FoodChoice == "A" || FoodChoice == "a"){
        money -= 2;
        cout << "You bought 'TextPet Low Grade Food'" << endl;
        cout << "Your current balance is $" << money << endl;
    }

        if(FoodChoice == "B" || FoodChoice == "a"){
            money -=5;
            cout << "You bought 'TextPet Medium Grade Food'" << endl;
            cout << "Your current balance is $" << money << endl;
        }

            if(FoodChoice == "C" || FoodChoice == "c"){
                money -=10;
                cout << "You bought 'TextPet High Grade Food'" << endl;
                cout << "Your current balance is $" << money << endl;
            }
}


//This will start in the beginning only, if the person has played before it will not show again.
void beginning()
{
    string TextPetName;
    string PlayerName;

    cout << "Welcome to the world of TextPet" << endl;
    cout << "TextPet is a interactive text pet that you can play with!" << endl;
    cout << "If you need help, just type in help at anytime" << endl;
    cout << "Its suggested you visit the help corner if this is your first time playing" << endl;
    cout << "\n";
    cout << "Press Enter to begin" << endl;
    cin.get();

    //Enter your name
    cout << "Ok lets start by entering your name" << endl;
    cout << "\n";
    getline(cin, PlayerName);
    cout << "\n";

    //Name your TextPet
    cout << "what do you want to name your new TextPet?" << endl;
    getline(cin, TextPetName);
    cout << "\n;";
}


//The player can level up their TextPet
void LevelUp()
{


}


//These are achievements that the player can earn
void Achievements()
{



}


//This is the Arena where your TextPet can fight in.
void Arena()
{
    string ArenaChoice;

    cout << "Welcome to the arena which fight would you like to enter your pet in?" << endl;
    cout << "\n";
    cout << "A - Low Level" << endl;
    cout << "     " << "Requirements: Level 1-15" << endl;
    cout << "\n";
    cout << "B - " << endl;
    cout << "     " << "Requirements: Level 15-30" << endl;
    cout << "\n";
    cout << "C - " << endl;
    cout << "     " << "Requirements: Level 30-" << endl;
    cin >> ArenaChoice;

    if(ArenaChoice == "A" || ArenaChoice == "a"){
        cout << "test" << endl;
    }

        if(ArenaChoice == "B" || ArenaChoice == "b"){
            cout << "test" << endl;
        }
}
Last edited on
So how do i make the money in FeedTextPet replace the money value in Main using the Return Statement? i have been trying to do it for the past 8 hours but had no luck.
Last edited on
Doing it by return value is not the best way, in my opinion.

Change your FeedTextPet function to this:

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
//Feed TextPet
void FeedTextPet(int& money)
{
    string FoodChoice;



    cout << "What would you like to feed your TextPet?" << endl;
    cout << "\n";
    cout << "A - TextPet Low Grade Food" << endl;
    cout << "     " << "Cost: $2" << endl;
    cout << "     " << "     " << "Health Restored: 3 points" << endl;
    cout << "\n";
    cout << "B - TextPet Medium Grade Food" << endl;
    cout << "     " << "Cost: $5" << endl;
    cout << "     " << "     " << "Health Restored: 6 points" << endl;
    cout << "\n";
    cout << "C - TextPet High Grade Food" << endl;
    cout << "     " << "Cost: $10" << endl;
    cout << "     " << "     " << "Health Restored: 14 points" << endl;
    cin >> FoodChoice;

    if(FoodChoice == "A" || FoodChoice == "a"){
        money -= 2;
        cout << "You bought 'TextPet Low Grade Food'" << endl;
        cout << "Your current balance is $" << money << endl;
    }

        if(FoodChoice == "B" || FoodChoice == "a"){
            money -=5;
            cout << "You bought 'TextPet Medium Grade Food'" << endl;
            cout << "Your current balance is $" << money << endl;
        }

            if(FoodChoice == "C" || FoodChoice == "c"){
                money -=10;
                cout << "You bought 'TextPet High Grade Food'" << endl;
                cout << "Your current balance is $" << money << endl;
            }
}


The only difference is in the first line.

Also, change that declaration to

void FeedTextPet(int& money);
Again, the difference is very small. Just that & symbol added.

This will mean that the FeedTextPet function operates on the actual money variable, rather than on a copy of it. Thus, changes you make to it will still exist when the function finishes.

Topic archived. No new replies allowed.