Could someone find an obvious reason this while loop performs once and then breaks? I don't think the condition on the while loop is dropping it out. I must be when I call the formatted writers but I 'm not sure how to make it stay in the while loop. Any suggestion will help. thanks

while(transval!=0){
            System.out.println("Account#: " +cc.getAccountNo());
            System.out.println("Credit Limit: " + cc.getCreditLimit());
            System.out.println("Available Credit: " + cc.getAvailable());
            System.out.println("Outstanding Balance: " + cc.getBalance());
            System.out.println("Charge: " + cc.getAmount());
            System.out.println("Description; " + cc.getDescription());
            System.out.println("payment: " + cc.getPayment());
            System.out.println("Total Charges: " + cc.getTotalCharges());
            System.out.println("Total Payments " + cc.getTotalPayments());
            
            System.out.println("\n");
            System.out.println("Transaction (0=Quit, +$=charge, -$=payment, 9999=Limit increase): ");
            transval = Console.in.readDouble();
            if (transval == 0){
                break;
            }
            if (transval == 9999){
                cc.creditIncrease();
            }
            if (transval > 0) {
                System.out.println("Transaction description: ");
                transdesc = Console.in.readLine();
                transdesc = Console.in.readLine();
                cc.setAmount(transval);
                cc.setDescription(transdesc);
                cc.Transaction();
                
            } else if (transval < 0){
                cc.setAmount(transval);
                cc.setDescription("Payment");
                cc.setPayment(transval);
                cc.Transaction();
                
            }
        }

I didn't see your code, but I can't say except debug it!!

When debugging I often find it helpful to add some println statements to see exactly what is happening. In your case I would insert a println statement immediately after

transval=Console.in.readDouble();

Something like

System.out.println("### transaval = "+transval+"###");

will help find out what is happening to your variable. Obviously this is the only thing that can exit your while loop both in your condition and your break statement. I personally have never used Console.in but prefer to use an InputStreamReader class (often in conjunction with a BufferedReader) and then parse the input received. But I hope I have given you a pointer in finding your error.

When debugging I often find it helpful to add some println statements to see exactly what is happening. In your case I would insert a println statement immediately after

transval=Console.in.readDouble();

Something like

System.out.println("### transaval = "+transval+"###");

will help find out what is happening to your variable. Obviously this is the only thing that can exit your while loop both in your condition and your break statement. I personally have never used Console.in but prefer to use an InputStreamReader class (often in conjunction with a BufferedReader) and then parse the input received. But I hope I have given you a pointer in finding your error.

Thanks that's a start.

Just try and use true as your statement for the while and then break out of the loop...

while(true){
code...
if(transval==0){
break;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.