Function not working?

Hello fellow programmers. I'm somewhat new to C++ and I've always found Functions to be confusing, and usually when i try to use them they dont really work, and this is no exception.
I'm making a small, simple, RPG, with an inventory system using a bunch of bool variables seeing if you have the item. I know there are better ways, but its simple and easy to do. Here's the code regarding the inventory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
bool swordHave = 0;
bool acHave = 0;
bool rustedArmorHave = 0;
bool daggerHave = 0;
bool staffHave = 0;

bool itemPickedUp2 = 0;
bool itemPickedUp4 = 0;
short playerItemCount = 0;
void menuFunc();
          void menuFunc() {
				if(swordHave == 1) cout << "Sword\n";
				if(acHave == 1) cout << "Average Clothing\n";
				if(rustedArmorHave == 1) cout << "Rusted Armor\n";
				if(daggerHave == 1) cout << "Dagger\n";
				if(staffHave == 1) cout << "Staff\n";
				}


I have the following code for each location to reach the inventory (i still haven't coded to way to leave it.)

 
else if(userInput == 99) void menuFunc();


What's happening when i type 99 into the console, it will repeat the location's description (this also happens when i type any number that doesn't do anything.)

Thanks for reading, and any help is appreciated!
Last edited on
closed account (N36fSL3A)
Why aren't you using OOP? Not using it severely limits this program. With OOP you could have a player class, which has an array of Item objects, and easily handle it.
Using classes is probably something you will have to consider. But classes or not, you have to get a grip on function "mechanics". From the above code it is somewhat hard to see what might be wrong. What other else if clauses are there?

To help you, you would benefit using a debugger to follow the sequence the program follows and track variable values. In addition, you can use cout commands at strategic places to help seeing what's going on.
Last edited on
Topic archived. No new replies allowed.