當它運行中獎或損失從銀行獲得或添加後再次運行時,銀行被設置爲25美元的銀行而不是更新的銀行在while循環之外無法獲取int更新
int main()
{
srand(time(0));
int bank = 25;
int total;
char answer;
cout << "Come play Spin the Wheel. The wheel has numbers from 1-10." << endl
<< "If you spin an even number you lose that amount. If you spin" << endl
<< "an odd number you win that amount. You start with a 25$ bank." << endl;
cout << "Your bank is $" << bank << ". Would you like to spin the wheel? (y/n):" << endl;
cin >> answer;
while (toupper(answer) == 'Y')
{
int num = rand() % 10 + 1;
if (bank <= 10)
{
cout << "Sorry you must have more than 10$ to play" << endl;
}
else if (num % 2 == 0)
{
total = bank + num;
cout << "You spun a " << num << " and won $" << num << endl;
cout << "Your bank is now: $" << total << endl;
}
else
{
total = bank - num;
cout << "You spun a " << num << " and lost $" << num << endl;
cout << "Your bank is now: $" << total << endl;
}
cout << "Would you like to play Again (y/n) ?" << endl;
cin >> answer;
}
return 0;
}
當它運行時的輸贏採取或從銀行加入,然後再次運行該銀行重新設置爲25 $銀行沒有更新的銀行
你在哪裏更新銀行? – RyanTCB
它最初是cout <<「您的銀行現在是:$」<< bank + num << endl;但我試圖把它扔到一個單獨的變量下,這也不起作用 – Drewdinie
在結尾cout <<「你想再次玩(y/n)嗎?」 << endl; \t \t cin >> answer;它再次運行while循環。對不起,我真的很新,沒有別的辦法再次運行遊戲,至少得知 – Drewdinie