我刚学完随机函数的使用方法,所以我决定做一个小赌场游戏。但是,我的代码不会更新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;
}