PDA

View Full Version : need help debugging my code


x8o
01-24-2007, 04:33 AM
i am trying to understand how this while function works.


while (priceA >=0)
{
totalA += priceA;
priceA = Double.parseDouble(JOptionPane.showInputDialog
("Enter a purchase price in County A, -1 to quit"));
}
while (priceB >= 0)
{
totalB += priceB;
priceB = Double.parseDouble(JOptionPane.showInputDialog
("Enter a purchase price in County B, -1 to quit"));
}


i know the squiggly brackets make it so that while loop body is a block. however, what does the totalA/B += priceA/B; do? i know the JOptionPane is just another JOptionPane.

i'm trying to figure out how to get my while statement to work with my other code so that the loop continues until you enter -1 to quit. currently i have it working, however with this while statement, the answer is incorrect for the values for priceA/B do not get calculated into the total cost.

david_kw
01-24-2007, 08:20 AM
Is this Java or Javascript? It kind of looks like Java and this is a Javascript forum (different language).

But I still know what += means.

totalA += priceA;

is the same as

totalA = totalA + priceA;

The two statements are equivilent.

david_kw

Philip M
01-24-2007, 08:20 AM
"what does the totalA/B += priceA/B; do?"

Uh? :confused:

Ah, David has worked out what you mean!

x8o
01-24-2007, 09:15 AM
WOOPS .. damn it! yah this is java .. it belongs in the computer programming section =(