I am trying to have an array of strings that I want to loop through as a shop for a text game. I want to print out the array and then if the user enters that number then it will remove it from the array, but I'm not sure if I am doing the array wrong where it cant have spaces, or if it needs to be something else, or if my solution is wrong.
int choice() {
int choice;
std::cout << "\n\nWhat will you choose? ";
while (true) {
std::cin >> choice;
if (!std::cin) {
std::cout << "\n\nInvalid Choice. Enter again ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
continue;
} else
break;
}
return choice;
}
std::string items[17] = {
"Potion of Healing 3 Gold Pieces",
"Potion of Plant Control 2 Gold Pieces",
"Potion of Stillness 3 Gold Pieces",
"Potion of Insect Control 2 Gold Pieces",
"Potion of Anti-Poison 2 Gold Pieces",
"Holy Water 3 Gold Pieces",
"Ring of Light 3 Gold Pieces",
"Boots of Leaping 2 Gold Pieces",
"Rope of Climbing 3 Gold Pieces",
"Net of Entanglement 3 Gold Pieces",
"Armband of Strength 3 Gold Pieces",
"Glove of Missile Dexterity 2 Gold Pieces",
"Rod of Water-finding 2 Gold Pieces",
"Garlic Buds 2 Gold Pieces",
"Headband of Concentration 3 Gold Pieces",
"Fire Capsules 3 Gold Pieces",
"Nose Filters 3 Gold Pieces"};
for (int i = 0; i < sizeof(items); i++) {
std::cout << items[i];
}
std::cout << "0. Exit" << std::endl;
std::cout << "\nWhat items will you Purchse?" << std::endl;
pick = choice();