我刚学完如何使用随机功能,所以我决定做一个小赌场游戏.但是,我的代码不会更新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;
}
Run Code Online (Sandbox Code Playgroud)
Money + 10;
Run Code Online (Sandbox Code Playgroud)
是一个没有副作用的声明.你要
Money += 10;
Run Code Online (Sandbox Code Playgroud)
这相当于
Money = Money + 10;
Run Code Online (Sandbox Code Playgroud)
如果你写的话,请考虑一下
4 + 5;
Run Code Online (Sandbox Code Playgroud)
你期望4成为9什么?...
| 归档时间: |
|
| 查看次数: |
125 次 |
| 最近记录: |