Hello everyone,
I am having some trouble getting some code to work. What it needs to do is ask for a value input by the user, so e.g. "2", then ask again and again collecting the values and adding them up untill the user selects cancel and after doing so is shown the total addition of all the values they input.
So far it requests the values untill you hit cancel but when you hit cancel a new window showing the total values is not showing up. Here is the code:
import javax.swing.JOptionPane; public class Testing { public static void main (String[] args) { String inputBegin = JOptionPane.showInputDialog("Enter the first value:"); double firstInput = Double.parseDouble(inputBegin); double Number ; String numInput = ""; double Total; double newNumber = 0; do { numInput = JOptionPane.showInputDialog("Enter the next value or hit cancel to end:"); Number = Double.parseDouble(numInput); newNumber = newNumber + Number; Total = firstInput + newNumber; } while (numInput != null); JOptionPane.showMessageDialog(null, "£" + Total); } }