【发布时间】:2013-11-12 05:06:12
【问题描述】:
这是我目前正在使用的代码:
bool playCraps(int currentGame, bool detailPrint, char isBetting, int startingBet)
{
bool crapsResult = NULL;
int currentGameStorage[100];
int currentRoll = 1;
int point = roll2Dice();
int printingNumber = 0;
currentGameStorage[0] = point;
if(point == 7 || point == 11)
{
crapsResult = true;
}
else if(point == 2 || point == 3 || point == 12)
{
crapsResult = false;
}
else
{
crapsResult = NULL;
}
while(crapsResult != true || crapsResult != false)
{
currentGameStorage[currentRoll] = roll2Dice();
if(currentGameStorage[currentRoll] == point)
{
crapsResult = true;
}
else if(currentGameStorage[currentRoll] == 7)
{
crapsResult = false;
}
currentRoll += 1;
}
currentRoll -= 1;
if(detailPrint == true)
{
cout << "Game " << currentGame << ": ";
for(printingNumber = 0; printingNumber <= currentRoll; printingNumber += 1)
{
cout << currentGameStorage[printingNumber] << " ";
}
if(crapsResult == true)
{
cout << "win";
}
else if(crapsResult == false)
{
cout << "lose";
}
cout << endl;
}
return crapsResult;
}
每当我运行它时,它都会创建一个无文本的循环,终端中不会出现任何文本。函数 roll2Dice() 使用 rand() 函数模拟两个六面骰子的掷骰,并将两个结果相加。任何帮助将不胜感激。
【问题讨论】:
-
想想
while(crapsResult != true || crapsResult != false)是什么意思, -
我将其设置为 and 循环,但现在我的输出出现问题。它应该输出数组中的每个值,但现在它输出一个长负数,而不是 1 到 12 之间的数字列表
标签: c++ function loops while-loop