do-while cycle sum help...

Hi i am doing this parking lot program.

i have declared like this:

do{

double payment=rf.readDouble();

System.out.println("Amount to pay: "+payment);

double sum=0;

sum=sum+payment;

System.out.println(sum);

}while(ci !='n');

all the code is inside a do-while , as you can see.

What i want is that everytime a do--while cycle goes, the variable "sum" holds the payment of the first cycle, plus the payment of the second cycle, and so on., so i can have a total.

At the moment everytime a cycle goes, the "sum" value its the same as "payment".

what should i do to make this work?

thanks for any response...

[930 byte] By [deroka] at [2007-10-2 22:14:22]
# 1

> > double sum=0; //declare the sum outside the cycle

> do{

> double payment=rf.readDouble();

> System.out.println("Amount to pay: "+payment);

>

> sum+=payment; //use this rather then sum = sum + ...

> System.out.println(sum);

> }while(ci != 'n');

>

mvpa at 2007-7-14 1:31:18 > top of Java-index,Java Essentials,Java Programming...
# 2
thanks mvp
deroka at 2007-7-14 1:31:18 > top of Java-index,Java Essentials,Java Programming...