訪問http://voyager.deanza.edu/~bentley/ass5.html骰子游戲,需要我們與添加*一起數算自己每天輪流搖骰子
我的目標是嘗試匹配的樣本輸出,鏈接之前。我似乎無法克服的唯一障礙是如何在每行擲骰之前添加回合以及「*」。
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int roll();
int turn();
int main()
{
srand(time(0));
int gameTotal = 0;
while (gameTotal < 100)
{
gameTotal += turn();
cout << "Your total is now " << gameTotal << endl << endl;;
}
}
int turn()
{
int turnTotal = 0;
int temp;
for (int i = 0; i < 3; i++)
{
temp = roll();
if (temp == 7) break;
turnTotal += temp;
}
cout << "You scored " << turnTotal << " points for this turn" << endl;
return turnTotal;
}
int roll()
{
int die1 = rand() % 6 + 1;
int die2 = rand() % 6 + 1;
int sum = die1 + die2;
cout << "You rolled a " << die1 << " and " << die2 << ". " << "That's " << sum << endl;
return sum;
}
請說明您的具體問題或添加額外的細節,突顯你需要什麼。正如目前所寫,很難確切地說出你在問什麼。請參閱[如何提問](https://stackoverflow.com/help/how-to-ask)頁面以獲得澄清此問題的幫助。 – jotik
請分享你的任何代碼,並詳細描述你是如何「卡住」的。我們也不做你的功課。 – Sheph
感謝您的輸入。這個網站還是新手。只需附上我的代碼。抱歉不清楚。 –