-2

みなさん、配列をベクターで動作させようとしているので、プログラムを実行するたびにコードが「単語」という文字を表示しなくなります。ベクターで何かをする必要があると思いますが、いくつかのガイドを読みましたが、誰かが素晴らしい手順で私を助けることができるかどうかかなり混乱していますか? :)

編集: 基本的に、ベクトルを関数 playGame(); で動作させようとしています。毎回同じ単語が出てくるのではなく、別の単語を表示できるように、別名「単語」

これが私の現在のコードです:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int playGame(string word); 
string array[]= { "apple", "banana", "orange", "strawberry" }; 
vector<string> word (array, array+4); 

int main() 
{
int choice;
bool menu = true;
do{
cout <<"Please select one of the following options:  \n";

cout << "1: Play\n"
    "2: Help\n"
    "3: Quit\n";

cout << "Enter your selection (1, 2 and 3): ";
cin >> choice;
//*****************************************************************************
// Switch menu to display the menu.
//*****************************************************************************
    switch (choice)
 {
      case 1:
        cout << "You have chosen play\n";
        //int playGame(string word); 
        playGame("word");
        break;
     case 2:
        cout << "You have chosen help\n";
        cout << "Here is a description of the game Hangman and how it is    played:\nThe      word to guess is represented by a row of dashes, giving the number of letters, numbers and category. If the guessing player suggests a letter or number which occurs in the word, the other player writes it in all its correct positions";
        break; 
         case 3:
        cout << "You have chosen Quit, Goodbye.";
        break;
    default:
        cout<< "Your selection must be between 1 and 3!\n";

    }

}while(choice!=3);    
getchar();
getchar();


cout << "You missed " << playGame("programming");
cout << " times to guess the word programming." << endl;
}
4

2 に答える 2