I'm working on an inventory system as a challenge for the amount of c++ I currently know, I'm using an array with enumerated indices and initializing with value true or false. This is the code:
using namespace std;
enum items
{
LASER_RIFLE,
LASER_SWORD,
LASER_PISTOL,
PLASMA_LAUNCHER,
MAX_ITEMS
};
void playerInventory()
{
bool items[MAX_ITEMS];
items[LASER_RIFLE] = true;
items[LASER_SWORD] = false;
items[LASER_PISTOL] = false;
items[PLASMA_LAUNCHER] = true;
int itemName;
for (int item = 0; item <= MAX_ITEMS; ++item)
if (items[item] == true)
{
switch (itemName)
{
case 1:
cout << "Laser Rifle\n";
break;
case 2:
cout << "Laser Sword\n";
break;
case 3:
cout << "Laser Pistol\n";
break;
case 4:
cout << "Plasma Launcher \n";
break;
}
}
else
cout << "Not in Inventory\n";
}
The statement only evaluates true for Laser pistol, and false for everything else. I cannot figure out why this is.