我剛學完如何使用隨機功能,所以我決定做一個小型的賭場遊戲。但是,我的代碼不會更新double Money;
變量。那就是我無法設置,添加或減去這個變量的值。我無法確定發生這種情況的原因。爲什麼變量不變?
這裏是我的代碼:
int main()
{
double Money;//Variable Money;
srand (time(0));
int randomNumber;
randomNumber = (1+(rand() % 10));
cout << "\nEnter your Starting Money: ";
int Guess;
cin >> Money;
cout << "Your Starting money is: " << Money;
cout << "\nGuess the number between 1 and 10: ";
start:
cin >> Guess;
if(Guess == randomNumber)
{
Money + 10;
cout << "You were correct! The number was " << randomNumber << "!";
}
else
{
Money - 10;//Nothing Happens
cout << "You were wrong! Your money is now: " << Money << "\nRetry Please: ";
goto start;
}
char f;
cin >> f;
return 0;
}
你沒有設置變量,試試'Money = Money + 10' –