| | |
while loop
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 238
Reputation:
Solved Threads: 0
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
Java Syntax (Toggle Plain Text)
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!!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
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 Something like 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.
java Syntax (Toggle Plain Text)
transval=Console.in.readDouble();
java Syntax (Toggle Plain Text)
System.out.println("### transaval = "+transval+"###");
•
•
Join Date: Aug 2007
Posts: 238
Reputation:
Solved Threads: 0
•
•
•
•
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 afterSomething likejava Syntax (Toggle Plain Text)
transval=Console.in.readDouble();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.java Syntax (Toggle Plain Text)
System.out.println("### transaval = "+transval+"###");
Thanks that's a start.
![]() |
Similar Threads
- Help with gui loop. (C)
- Loop...without the loop (Java)
Other Threads in the Java Forum
- Previous Thread: Help on a reading from a file programming
- Next Thread: Lempel Ziv Encoding
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card character class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting researchinmotion scanner se server service set sms software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






