| | |
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 |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card chat class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting scanner se server service set sms socket software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






