好的,这对谷歌来说是一个难题。我想要的是一旦用户在库存数组中输入 10 个项目,我希望它清除控制台并讲述一个故事。我尝试过,但无论数组中有多少项目,它都会显示故事,因为我将数组定义为最大 10。我还试图找到一种方法来交换数组中的项目。我的意思是我希望控制台询问用户是否愿意将 {item which is already in the array} 换成 {item2} y 或 n?
问题是它不显示项目名称只是在故事示例中输出的数组中的位置。显示“你想用 1 交换附魔剑吗”。然后,如果您点击是,它不会将其添加到数组中。无论如何它也绕过了我的谢谢
void tellStory(InventoryRecord list[], int& size)
{
int numOfRecs = size;
int pos = rand()%numOfRecs; //Generate a random position of the item
//Generate item to trade, I'll refer to it as "Item
int TRADE_CHANCE = 0;
const string str = "Enchanted Sword";
InventoryRecord recList[MAX_SIZE];
if (numOfRecs == MAX_SIZE) {
system("cls");
cout << "So your ready to begin your quest!" << endl << endl;
cout << "Before you begin I would like the opportunity to trade you a rare item!" << endl << endl;
cout << "Would you like to trade" << pos << "for" << str << "?" << endl << endl;
cout << "Yes or No? ";
cin >> choice;
if (toupper(choice) == 'Y')
(rand()%100 < TRADE_CHANCE);
(recList[pos], str);//Here add the trading stuff, which is some text, user input(y/n) and replacing realist[pos] = Item, etc
}
else {
cout << "Thanks anyways!" << endl << endl;
system("pause");
}
system("cls");
}