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;
coutwordOne[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;
coutwordOne[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问题的注释。