-1

ちょっと基本的に私は2つの機能を持っています:

void Inventory:: showInventory()
{
    char input[80];
    cin >> input;
    char inventoryRequest[] = "i";
    //compare the player input to inventoryRequest (i) to see if they want to
    //look at inventory.
    int invent = strcmp (input,inventoryRequest);

    if(invent == 0) {
        //vector<string> inventory;
        cout << "You have " << inventory.size() << " items.\n";
        cout << "\n******Inventory******";
        cout << "\nYour items:\n";

        for (int i= 0; i< inventory.size(); ++i) {
            cout<< inventory[i] << endl;
        }
    }

}

void Inventory :: displayInventory(const string str) {
    char input = 0;
    do
    {
        cout << str << endl;
        cin >> input;
    }
    while((input != 'i') && (input != 'I') && (input != 'n') && (input != 'N'));
    showInventory();
    //return input;
}

showInventory はプレーヤーの入力を i と比較します。在庫を表示すると、ユーザーは i または n を押すことができます。i でインベントリを表示し、n でスキップします。しかし、私が押されたとき。二重線の原因となります。

つまり、インベントリを表示するには、i を 2 回押す必要があります。

これが起こらないようにするために、私は多くのことを試みました。しかし、私は成功しておらず、ほとんどの場合、インベントリをまったく表示できません。

誰でもこれで私を助けることができますか?前もって感謝します。

4

1 に答える 1

1

次のように、の入力にパラメーターを使用しvoid Inventory::showInventory()、2 番目の を削除してみてくださいcin

void Inventory:: showInventory(char input)
{
    //char input[80];
    //cin >> input;
    //char inventoryRequest[] = "i";
    //int invent = strcmp (input,inventoryRequest);
    //compare the player input to inventoryRequest (i) to see if they want to look at inventory.
    //if(invent == 0)  // REPLACE THIS WITH THE LINE BELOW
    if(input == 'i')

そして、それを呼び出すときは、次のようにします。

    showInventory(input);
于 2012-11-29T22:02:21.107 に答える