| | |
Accumulators
![]() |
•
•
Join Date: Aug 2007
Posts: 58
Reputation:
Solved Threads: 0
Hello guys. I'm having a bit of difficulty with adding totals. I know how it's suppose to work but I'm not seeing what I'm doing wrong. If I want to add my total each time I hit the total button how can I do it. When I try to add it, it never works but lets say I do total = total +10;, it will do it only once no matter how many times I press the total button. This is an example of the code I have for now. So basically with this code, anytime I hit the total button it should keep adding 5 to the total. So the first time it will be 5, second time 10 and so forth. Thanks in advance!
java Syntax (Toggle Plain Text)
total = 5; newtotal = 0.0; public void actionPerformed(ActionEvent e) { String arg = e.getActionCommand(); if(arg == "Total") { total = total + newtotal; } }
Um, you can 0 to a value all day and it won't change...
Java Syntax (Toggle Plain Text)
total = 5; newtotal = 0.0;
•
•
Join Date: Aug 2007
Posts: 58
Reputation:
Solved Threads: 0
I found out what I had to do. It's lame when you find out you make the simplest of mistakes. I needed to add an extra line newtotal = total;. Then everytime i pick the total button it adds the old total to the new total. My new code with it implemented is below, incase others may have the same question in the future. Thanks again Ezz.
java Syntax (Toggle Plain Text)
total = 5; newtotal = 0.0; public void actionPerformed(ActionEvent e) { String arg = e.getActionCommand(); if(arg == "Total") { total = total + newtotal; newtotal = total; } }
![]() |
Similar Threads
- convert ASCii chacracter to decimal (Assembly)
- Accumulators and counters (VB.NET)
- The switch statement (C++)
- Loops (C++)
- Help please with incorrect gas mileage calculation (C)
- Game ON (Geeks' Lounge)
Other Threads in the Java Forum
- Previous Thread: Help On how to set time
- Next Thread: JRadioButtons not working! need help urgently
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






