Note that there are some explanatory texts on larger screens.

plurals
  1. POCan a variable in c++ add its old value plus its new value?
    primarykey
    data
    text
    <p>Is there a way in c++ for a single variable to maintain its same value and when added to, it will add its last value with the new one? for example, I am writing a program where the user can enter as many "checks" and "deposits" they received through the day, and at the end of the day the program will let the user know how much he made throughout the day</p> <p>here is what I have so far</p> <pre><code>#include &lt;cstdlib&gt; #include &lt;iostream&gt; using namespace std; int main(int argc, char *argv[]) { system("Color 0E"); int cashBalance = 1000; int check; int depo; double toDepo = depo * 0.3; double totalDepo = depo - toDepo; int loop = 5; int choice; cout &lt;&lt; "check = 1, deposit = 2, add = 3, clear the screen = 4, close = 0\n" &lt;&lt; endl; while (loop == 5){ cout &lt;&lt; "Would you like to enter a depoist or a check?\n" &lt;&lt; endl; cin &gt;&gt; choice; //determines whether or not to close the program if(choice == 0 || depo == 0 || check == 0){ return 0; }//end close if //choses which type of input to make if( choice == 1){ cout &lt;&lt; "Please enter check\n" &lt;&lt; endl; cin &gt;&gt; check; } else if(choice == 2){ cout &lt;&lt; "Please enter deposit\n" &lt;&lt; endl; cin &gt;&gt; depo; }//end if if(choice == 3 || depo == 3 || check == 3){ cout &lt;&lt; "Total = " &lt;&lt; (cashBalance - check) + totalDepo &lt;&lt; endl; } //clear the console screen if(choice == 4 || depo == 4 || check == 4){ system("cls"); cout &lt;&lt; "check = 1, deposit = 2, add = 3, clear the screen = 4, close = 0\n" &lt;&lt; endl; } }//end while loop system("PAUSE"); return EXIT_SUCCESS; }//end of program </code></pre> <p>the problem is that i need the variable "check" and "depo" to be able to add the users first value and the second value to get the new value. right now all it does is display the last value the user inserted.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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