我正在做一个在 C++ 中刺激 ATM 并且累加器有一些问题的项目,我的问题是:我正在使用 switch(这里是案例 1)来更改在包含 switch 的函数中声明的 2 个变量的值( ),但是值仅在案例 1 内部发生变化,并且它们将自身重置为原始值(如 const 声明),因此当我尝试打印检查和保存(在案例 3 和 4 中)时,它会打印出原始金额(1000) . 所以我不知道我在这里做错了什么。问题不在于金额,我尝试用数值替换金额,但仍然不起作用。请帮忙
int transactions()
{
double checking = 1000.00, saving = 1000.00;
double amount;
switch (inputRange(menu()))
{
case 1: system("cls");
amount = getAmount("Enter an amount to transfer from checking to saving: ");
checking -= amount;
saving += amount;
cout << checking << " " << saving; // they only change inside case 1
cout << "\nTransaction completed! \n\nPress ENTER to return to main menu...";
cin.ignore(99,'\n');
break;
更新***我已经知道了伙计们,谢谢,只是忘记了&,这行得通
int transactions(double &checkBal, double &saveBal)
{
double amount;
//set precision
cout << fixed << showpoint << setprecision(2);
switch (inputRange(menu()))
{
case 1: system("cls");
checkingToSaving (getAmount("Enter an amount to transfer from checking to saving: "), checkBal, saveBal);
cout << "\nTransaction completed! \n\nPress ENTER to return to main menu...";
cin.ignore(99,'\n');
break;