Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 比较两个数组的困难 #包括 #包括 #包括 使用名称空间std; int main() { char-wordOne[5][9]={{“大象”}, {“帝国”}, {“绝对”}, {“苦艾酒”}, {“计算机”}; char hangman[9]={********}; 猜字符; INTR; srand(时间(0)); r=rand()%5; 字一[r]; 无法_C++_Arrays - Fatal编程技术网

C++ 比较两个数组的困难 #包括 #包括 #包括 使用名称空间std; int main() { char-wordOne[5][9]={{“大象”}, {“帝国”}, {“绝对”}, {“苦艾酒”}, {“计算机”}; char hangman[9]={********}; 猜字符; INTR; srand(时间(0)); r=rand()%5; 字一[r]; 无法

C++ 比较两个数组的困难 #包括 #包括 #包括 使用名称空间std; int main() { char-wordOne[5][9]={{“大象”}, {“帝国”}, {“绝对”}, {“苦艾酒”}, {“计算机”}; char hangman[9]={********}; 猜字符; INTR; srand(时间(0)); r=rand()%5; 字一[r]; 无法,c++,arrays,C++,Arrays,将wordOne[hangman[x]][x]更改为wordOne[r][x]。 另外,我建议不要在for循环中打印endl,因为它在不同的行上打印每个字符。将wordOne[hangman[x]][x]更改为wordOne[r][x]。 另外,我建议不要在for循环中打印endl,因为它将每个字符打印在不同的行上。wordOne[hangman[x]][x]比方说x=1这在代码中等同于wordOne['*'][1]。这不应该是wordOne[r][x]==guess?我添加了一个int来跟踪猜

wordOne[hangman[x]][x]
更改为
wordOne[r][x]

另外,我建议不要在for循环中打印
endl
,因为它在不同的行上打印每个字符。

wordOne[hangman[x]][x]
更改为
wordOne[r][x]

另外,我建议不要在for循环中打印
endl
,因为它将每个字符打印在不同的行上。

wordOne[hangman[x]][x]
比方说
x=1
这在代码中等同于
wordOne['*'][1]
。这不应该是
wordOne[r][x]==guess
?我添加了一个
int
来跟踪猜测的数量,并在while循环中添加了一个检查来查看用户是否猜测了最大次数

#include<iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
char wordOne[5][9] = { {"elephant"},
                       {"imperial"},
                       {"absolute"},
                       {"absinthe"},
                       {"computer"} };

char hangman[9] = {"********"};

char guess;

int r;
srand( time(0));
r = rand()%5;
wordOne[r];

cout << "Guess the secret eight letter word before you run out of guesses! Go: " << endl;

for (int x = 0; x < 8; ++x)

cout << hangman[x] << endl;
cin >> guess;

while (hangman[0] == '*' || hangman[1] == '*' || hangman[2] == '*' || hangman[3] == '*' || hangman[4] == '*' || hangman[5] == '*' || hangman[6] == '*' || hangman[7] == '*')

{
cout << "Guess the secret eight letter word before you run out of guesses! Go: ";
for(int x = 0; x < 8; ++x)
        cout << hangman[x];
        cout << endl;
        cin >> guess;

    for(int x = 0; x < 8; ++x)
    {
        if (wordOne[hangman[x]][x] == guess)
            {
                hangman[x] = guess;
            }
    }

for(int x = 0; x < 8; ++x)
    cout << hangman[x] << endl;
}

system("PAUSE");
return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
char-wordOne[5][9]={{“大象”},
{“帝国”},
{“绝对”},
{“苦艾酒”},
{“计算机”};
char hangman[9]={********};
猜字符;
INTR;
srand(时间(0));
r=rand()%5;
字一[r];
整数=10;

cout
wordOne[hangman[x]][x]
让我们假设
x=1
这在代码中等同于
wordOne['*'][1]
。它不应该是
wordOne[r][x]==guess
?我添加了一个
int
来跟踪猜测的数量,并在while循环中添加了一个检查来查看用户是否猜测了最大次数

#include<iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
char wordOne[5][9] = { {"elephant"},
                       {"imperial"},
                       {"absolute"},
                       {"absinthe"},
                       {"computer"} };

char hangman[9] = {"********"};

char guess;

int r;
srand( time(0));
r = rand()%5;
wordOne[r];

cout << "Guess the secret eight letter word before you run out of guesses! Go: " << endl;

for (int x = 0; x < 8; ++x)

cout << hangman[x] << endl;
cin >> guess;

while (hangman[0] == '*' || hangman[1] == '*' || hangman[2] == '*' || hangman[3] == '*' || hangman[4] == '*' || hangman[5] == '*' || hangman[6] == '*' || hangman[7] == '*')

{
cout << "Guess the secret eight letter word before you run out of guesses! Go: ";
for(int x = 0; x < 8; ++x)
        cout << hangman[x];
        cout << endl;
        cin >> guess;

    for(int x = 0; x < 8; ++x)
    {
        if (wordOne[hangman[x]][x] == guess)
            {
                hangman[x] = guess;
            }
    }

for(int x = 0; x < 8; ++x)
    cout << hangman[x] << endl;
}

system("PAUSE");
return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
char-wordOne[5][9]={{“大象”},
{“帝国”},
{“绝对”},
{“苦艾酒”},
{“计算机”};
char hangman[9]={********};
猜字符;
INTR;
srand(时间(0));
r=rand()%5;
字一[r];
整数=10;

cout
wordOne[hangman[x]][x]
让我们假设
x=1
这在代码中等同于
wordOne['*'][1]
。它不应该是
wordOne[r][x]==guess
吗?你还应该有一个已经猜到的字母数组来进行检查,这样用户就不能一直输入已经猜到的字母。嗯,
如果(wordOne)[[hangman]…
看起来不正确。请尝试
如果(wordOne[r][x]==guess)
wordOne[hangman[x]][x]
假设
x=1
这在代码中等同于
wordOne['*'][1]
。这不应该是
wordOne[r][x]==guess
?您还应该有一个已经猜到的字母数组进行检查,这样用户就不能继续输入已经猜到的字母。嗯,
如果(wordOne[hangman]…
看起来不正确。请尝试
如果(wordOne[r][x]==guess)
。非常感谢!我不敢相信修复有多简单。你太棒了。非常感谢!我不敢相信修复有多简单。你太棒了。你增强了代码,但是OP的代码中有什么问题,你做了什么来解决它?@CaptainObvlious哦,是的,我忘了将OP的问题添加到我的answe中r、 您增强了代码,但OP的代码中有什么问题?您做了什么来解决它?@CaptainObvlious哦,是的,我忘了在我的答案中添加OP问题的注释。