私は絞首刑執行人のゲームを作っていますが、その一部に問題があります。
ファイルからランダムな単語を選択しましたが、その単語を一連のアンダーソクア_ _として表示し、選択した文字をアンダーソクアの位置に一致させたいと思います。
cout <<"1. Select to play the game\n";
cout <<"2. Ask for help\n";
cout <<"3. Select to quit the game\n";
cout << "Enter a selection: ";
int number;
cin >> number;
while(number < 1 || number > 3 || cin.fail())
{
if(cin.fail())
{
cin.sync();
cin.clear();
cout << "You have not entered a number, please enter a menu selection between 1 and 3\n";
cin >> number;
}
else
{
cout << "Your selection must be between 1 and 3!\n";
cin >> number;
}
}
switch (number)
{
case 1:
{
string word;
string name;
cout << " Whats your name? ";
cin >> name;
Player player();
ifstream FileReader;
FileReader.open("words.txt");
if(!FileReader.is_open())
cout << "Error";
//this is for the random selection of words
srand(time(0));
int randnum = rand()%10+1;
for(int counter = 0; counter < randnum; counter++)
{
getline(FileReader, word, '\n');
}
cout << "my word: " << word << "\n";
// get length of word
int length;
//create for loop
for(int i = 0; i < length; i++)
cout << "_";
//_ _ _ _ _
SetCursorPos(2,10);
FileReader.close();
break;