Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.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++制作一个岩石、纸张、剪刀代码。然而,当我试图将玩家猜测与计算机猜测进行比较时,我发现标题中有错误,甚至更多。这是我的代码: #include <stdio.h> #include <iostream> #include <random> void RocPaprSkisors () { std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<double> dist(1, 4); std::cout << dist(mt) << "\n"; int player_guess; std::cout << "Hello! Welcome to Rock, Paper, Scissors!" << std::endl; std::cout << "You have to try and beat the computer by choosing either rock, paper, or scissors" << std::endl; std::cout << "Rock beats scissors, scissors beats paper, and paper beats rock." << std::endl; std::cout << "Please guess 1 for paper, 2 for rock, or 3 for scissors" << std::endl; std::cin >> player_guess; if (player_guess == dist(mt)) { std::cout << "You tied!" << std::endl; std::cout << dist(mt) << std::endl; } else { if (player_guess == 1 and dist(mt) < 3 and >= 2) { std::cout << "The computer guessed rock! That means you win!" << std::endl; } else { if (player_guess == 2 and dist(mt) >= 1 and < 2) { std::cout << "The computer guessed paper. That means you be loser. :(" << std::endl; } else { if (player_guess == 1 and dist(mt) >= 3 and <= 4) { std::cout << "The computer guessed scissors. That means you be loser. :(" << std::endl; } else { if (player_guess == 3 and dist(mt) >= 1 and < 2) { std::cout << "The computer guessed paper!. That means you win!" << std::endl; } else { if (player_guess == 2 and dist(mt) >= 3 and <= 4) { std::cout << "The computer guessed scissors! That means you win!" << std::endl; } else { if (player_guess == 3 and dist(mt) >= 2 and < 3) { std::cout << "The computer guessed rock. That means you be loser. :(" << std::endl; { } } } } } } } int main () { RocPaprSkisors (); return 0; } #包括 #包括 #包括 无效的 洛帕斯基索() { std::随机_装置rd; 标准:mt19937 mt(rd()); 标准:均匀实分布区(1,4); std::cout_C++_Compiler Errors - Fatal编程技术网

在'&燃气轮机='; 我现在正在用C++制作一个岩石、纸张、剪刀代码。然而,当我试图将玩家猜测与计算机猜测进行比较时,我发现标题中有错误,甚至更多。这是我的代码: #include <stdio.h> #include <iostream> #include <random> void RocPaprSkisors () { std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<double> dist(1, 4); std::cout << dist(mt) << "\n"; int player_guess; std::cout << "Hello! Welcome to Rock, Paper, Scissors!" << std::endl; std::cout << "You have to try and beat the computer by choosing either rock, paper, or scissors" << std::endl; std::cout << "Rock beats scissors, scissors beats paper, and paper beats rock." << std::endl; std::cout << "Please guess 1 for paper, 2 for rock, or 3 for scissors" << std::endl; std::cin >> player_guess; if (player_guess == dist(mt)) { std::cout << "You tied!" << std::endl; std::cout << dist(mt) << std::endl; } else { if (player_guess == 1 and dist(mt) < 3 and >= 2) { std::cout << "The computer guessed rock! That means you win!" << std::endl; } else { if (player_guess == 2 and dist(mt) >= 1 and < 2) { std::cout << "The computer guessed paper. That means you be loser. :(" << std::endl; } else { if (player_guess == 1 and dist(mt) >= 3 and <= 4) { std::cout << "The computer guessed scissors. That means you be loser. :(" << std::endl; } else { if (player_guess == 3 and dist(mt) >= 1 and < 2) { std::cout << "The computer guessed paper!. That means you win!" << std::endl; } else { if (player_guess == 2 and dist(mt) >= 3 and <= 4) { std::cout << "The computer guessed scissors! That means you win!" << std::endl; } else { if (player_guess == 3 and dist(mt) >= 2 and < 3) { std::cout << "The computer guessed rock. That means you be loser. :(" << std::endl; { } } } } } } } int main () { RocPaprSkisors (); return 0; } #包括 #包括 #包括 无效的 洛帕斯基索() { std::随机_装置rd; 标准:mt19937 mt(rd()); 标准:均匀实分布区(1,4); std::cout

在'&燃气轮机='; 我现在正在用C++制作一个岩石、纸张、剪刀代码。然而,当我试图将玩家猜测与计算机猜测进行比较时,我发现标题中有错误,甚至更多。这是我的代码: #include <stdio.h> #include <iostream> #include <random> void RocPaprSkisors () { std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<double> dist(1, 4); std::cout << dist(mt) << "\n"; int player_guess; std::cout << "Hello! Welcome to Rock, Paper, Scissors!" << std::endl; std::cout << "You have to try and beat the computer by choosing either rock, paper, or scissors" << std::endl; std::cout << "Rock beats scissors, scissors beats paper, and paper beats rock." << std::endl; std::cout << "Please guess 1 for paper, 2 for rock, or 3 for scissors" << std::endl; std::cin >> player_guess; if (player_guess == dist(mt)) { std::cout << "You tied!" << std::endl; std::cout << dist(mt) << std::endl; } else { if (player_guess == 1 and dist(mt) < 3 and >= 2) { std::cout << "The computer guessed rock! That means you win!" << std::endl; } else { if (player_guess == 2 and dist(mt) >= 1 and < 2) { std::cout << "The computer guessed paper. That means you be loser. :(" << std::endl; } else { if (player_guess == 1 and dist(mt) >= 3 and <= 4) { std::cout << "The computer guessed scissors. That means you be loser. :(" << std::endl; } else { if (player_guess == 3 and dist(mt) >= 1 and < 2) { std::cout << "The computer guessed paper!. That means you win!" << std::endl; } else { if (player_guess == 2 and dist(mt) >= 3 and <= 4) { std::cout << "The computer guessed scissors! That means you win!" << std::endl; } else { if (player_guess == 3 and dist(mt) >= 2 and < 3) { std::cout << "The computer guessed rock. That means you be loser. :(" << std::endl; { } } } } } } } int main () { RocPaprSkisors (); return 0; } #包括 #包括 #包括 无效的 洛帕斯基索() { std::随机_装置rd; 标准:mt19937 mt(rd()); 标准:均匀实分布区(1,4); std::cout,c++,compiler-errors,C++,Compiler Errors,您的代码中有两个问题: 如果您有需求,可以用数学方法编写1

您的代码中有两个问题:

如果您有需求,可以用数学方法编写
1
,您不能将其表示为:

if( a > 1 and < 5 )
if(a>1和<5)
它必须是:

if( a > 1 and a < 5 )
if(a>1和a<5)
因为这是一种编程语言,而不是一种编写数学方程的语言。这个问题会导致语法错误


现在您的程序中出现逻辑错误-您无法调用
dist()
每次调用都会生成新的随机值。您需要的是调用它一次,请记住在变量中,并在以下逻辑中使用它。您可能不需要首先生成类型为
double
的随机值,因为您需要[1,3]中的整数范围

编译器不知道将
=2
计算为什么,因为您没有说明它(语法不正确)

您可能想做的是:

if (player_guess == 1 && dist(mt) < 3 && dist(m) >= 2)
if(玩家猜==1&&dist(mt)<3&&dist(m)>=2)

if(玩家猜==2&&dist(mt)>=1&&dist(m)<2)
等等


这回答了你的问题吗?

编译器抱怨说
=2
不是任何可以按原样计算的东西。应该是什么
=2
?你可能是想写
dist(mt)>=2
.a)读取b)替换
&
c)替换
dist(mt)<3和>=2
dist(mt)<3和&dist(mt)>=2
@UKMonkey但是
&
:@MichaWiedenmann fair shout…虽然当人们发布代码看起来像是打开的,并且想知道为什么他们没有得到帮助时,一滴眼泪也不会流下来!@UKMonkey绝对是。但是这很有趣,这就是为什么我添加了评论。如果我写
如果(rand()<3和rand()>=2)
你能称之为正确答案吗?谢谢你的回答,但是我如何将数字存储在一个单独的变量中,这样它就不会生成新的变量?@Need\u help
std::uniform\u real\u dist(1,4);int comp\u guess=dist(mt);
并在使用
player\u guess
if (player_guess == 1 && dist(mt) < 3 && dist(m) >= 2)
if (player_guess == 2 && dist(mt) >= 1 && dist(m) < 2)