大家好,我正在尝试让数组与向量一起使用,因此每次运行我的程序时,我的代码都不会出现字母“单词”。我想我需要对向量做一些事情,但我已经阅读了一些指南,但是如果有人可以帮助我完成那些很棒的步骤,我会很困惑?:)
编辑:基本上我试图让我的向量使用函数 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;
}