Note that there are some explanatory texts on larger screens.

plurals
  1. POchanging datas inside switch(), accumulation
    text
    copied!<p>Im doing a project that stimulate the ATM in C++ and having some troubles with the accumulators, my question is: I am use switch (here is case 1) to change the values of 2 variables which are declared inside the function that contains the switch(), however the values only change inside case 1 and they reset themselves to the original value (like const declaration), so when I try to print the checking and saving (in case 3 and 4) it prints out the original amount (1000). So I dont know what I did wrong here. Problem is not with the amount, I have tried replacing amount with a numeric value but still doesnt work. Please help</p> <pre><code>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 &lt;&lt; checking &lt;&lt; " " &lt;&lt; saving; // they only change inside case 1 cout &lt;&lt; "\nTransaction completed! \n\nPress ENTER to return to main menu..."; cin.ignore(99,'\n'); break; </code></pre> <p>updates*** I already got it guys, thanks, just forgot about the &amp;, this works</p> <pre><code> int transactions(double &amp;checkBal, double &amp;saveBal) { double amount; //set precision cout &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; setprecision(2); switch (inputRange(menu())) { case 1: system("cls"); checkingToSaving (getAmount("Enter an amount to transfer from checking to saving: "), checkBal, saveBal); cout &lt;&lt; "\nTransaction completed! \n\nPress ENTER to return to main menu..."; cin.ignore(99,'\n'); break; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload