Page 2 of 2 FirstFirst 12
Results 21 to 22 of 22
  1. #21
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by passingTime View Post
    I've tried this and i'm back to how i was before. It would add each entered value and straight after show it. So I input 2, it shows me 2, i input another 2, it shows me 4, i input 4, it shows me 8, i input 12, it shows me 20. It will keep doing that showing a dialog box requesting input with OK and Cancel then when i hit OK the show dialog box with the total amount and an OK button.


    Here is the code, much simpler but i'm still unsure how to make it only show the total when Cancel is hit:

    Java Code:
    import javax.swing.JOptionPane;
    public class testing
    {
    	public static void main (String[] args)
    	{
    
    	double total = 0.0;
    	String valueInput = "";
    	
    	
    	
    	while (valueInput != null)
    	{
    	
    		valueInput = JOptionPane.showInputDialog("Enter a value:");
    		if (valueInput != null)	
    		{
    			double numInput = Double.parseDouble(valueInput);
    			total = total + numInput;
    		}
    	
    	JOptionPane.showMessageDialog(null, "" + total);
    }
    }
    }

    Please look again at my pseudo-code and it shows you. Also, you must line up your braces else you won't know where you're putting the code to display the total.

  2. #22
    passingTime is offline Member
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Default

    *blushes* my bad

    Thanks so much for your help and patience. I was just hurrying that last one that's why i missed it :S

    I'm starting to wonder if that was the problem to begin with....
    Last edited by passingTime; 02-27-2011 at 11:17 PM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •