C++;Do/While循环和If/Else:Dice游戏——第75行错误:预期;而";“之前”;“不能”如何解决这个问题? 初学者编码器——第一C++类.< /P>
我在第75行之后不断出错,我无法找出哪里出了错。我知道我的代码很粘…我需要帮助清理它。有人知道我如何正确编码吗 这是任务: 骰子(如果/否则,循环,随机): 使用if/else、循环和随机数,编写一个骰子游戏程序,用户在其中掷2个骰子,并决定是“持有”这些数字还是再次掷骰子。它应该让用户滚动任意次数,直到他们抓住为止 然后计算机也应该掷2个骰子。游戏的目的是获得比电脑更高的分数 === 提示:使用随机数b/w 1-6,生成4个随机数 当我试图构建程序时,我遇到了一系列错误,并且不知道我做错了什么(试图自己调试)。以下是错误:C++;Do/While循环和If/Else:Dice游戏——第75行错误:预期;而";“之前”;“不能”如何解决这个问题? 初学者编码器——第一C++类.< /P>,c++,loops,if-statement,random,do-while,C++,Loops,If Statement,Random,Do While,我在第75行之后不断出错,我无法找出哪里出了错。我知道我的代码很粘…我需要帮助清理它。有人知道我如何正确编码吗 这是任务: 骰子(如果/否则,循环,随机): 使用if/else、循环和随机数,编写一个骰子游戏程序,用户在其中掷2个骰子,并决定是“持有”这些数字还是再次掷骰子。它应该让用户滚动任意次数,直到他们抓住为止 然后计算机也应该掷2个骰子。游戏的目的是获得比电脑更高的分数 === 提示:使用随机数b/w 1-6,生成4个随机数 当我试图构建程序时,我遇到了一系列错误,并且不知道我做错了什么
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
||In function 'int main()':|
|75|error: expected 'while' before 'cout'|
|75|error: expected '(' before 'cout'|
|75|error: expected ')' before ';' token|
|87|error: expected 'while' before 'While'|
|87|error: expected '(' before 'While'|
|87|error: 'While' was not declared in this scope|
|87|error: expected ')' before ';' token|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
这是我目前掌握的代码——有人能给我看一下正确的代码吗
#include <iostream>
#include <cstdio>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main()
{
srand(time(0));
int Roll1 = 1+(rand()%6);
int Roll2 = 1+(rand()%6);
int UserRoll = Roll1 + Roll2;
int Roll3 = 1+(rand()%6);
int Roll4 = 1+(rand()%6);
int ComputerRoll = Roll3 + Roll4;
string Hold;
string ThrowDice;
string Again;
do
{
do
{
cout << "Please enter \"throw\" (lowercase) to roll the dice: ";
cin >> ThrowDice;
} while(ThrowDice != "throw");
do
{
cout << "You rolled: " << Roll1 << " and " << Roll2 << endl;
cout << "Would you like to hold onto these numbers or roll again? " << endl;
cout << "Enter (lowercase) \"hold\" to keep this roll, or \"throw\" to roll again): ";
cin >> Hold;
if (Hold != "hold" && Hold != "throw")
{
cout << "Your choice isn't valid! Please try again by typing \"hold\" or \"throw\": " << endl;
}
}while (Hold != "hold" && Hold != "throw");
do
{
if (Hold == "hold")
{
cout << "You chose to keep these numbers, totaling: " << UserRoll << endl;
cout << "The computer rolled " << Roll3 << " and " << Roll4 << " totaling: " << ComputerRoll << endl;
} break;
if (Hold == "throw")
{
cout << "You chose to roll again. " << endl;
}
}while (Hold == "throw");
do
{
if (UserRoll < ComputerRoll)
{
cout << "Sorry. You lose. " << endl;
} break;
if (ComputerRoll < UserRoll)
{
cout << "Congratulations! You win! " << endl;
} break;
if (ComputerRoll == UserRoll)
{
cout << "It's a draw. " << endl;
} break;
}
cout << "Would you like to play again? [Yes/No]: " << endl;
cin >> Again;
if (Again == "Yes")
{
continue;
}
else if (Again == "No")
{
break;
}
}While (Again == "Yes");
return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
srand(时间(0));
int Roll1=1+(rand()%6);
int Roll2=1+(rand()%6);
int UserRoll=Roll1+Roll2;
int Roll3=1+(rand()%6);
int Roll4=1+(rand()%6);
int ComputerRoll=Roll3+Roll4;
字符串保持;
弦抛;
再串一次;
做
{
做
{
杂碎;
}while(ThrowDice!=“扔”);
做
{
cout最后一个do
代码块需要while()“< /P> >做所有的<代码>……< /COD>循环真的有<代码> do <代码>和<代码> > < /C> >。<代码> > 不是有效的C++关键字,<代码>而另一方面谢谢!我不知道我怎么错过了这个。这非常有用…现在有一个工作程序再一次!