while loop

Thread Solved

Join Date: Aug 2007
Posts: 238
Reputation: ceyesuma is an unknown quantity at this point 
Solved Threads: 0
ceyesuma ceyesuma is offline Offline
Posting Whiz in Training

while loop

 
0
  #1
Sep 22nd, 2007
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

  1. while(transval!=0){
  2. System.out.println("Account#: " +cc.getAccountNo());
  3. System.out.println("Credit Limit: " + cc.getCreditLimit());
  4. System.out.println("Available Credit: " + cc.getAvailable());
  5. System.out.println("Outstanding Balance: " + cc.getBalance());
  6. System.out.println("Charge: " + cc.getAmount());
  7. System.out.println("Description; " + cc.getDescription());
  8. System.out.println("payment: " + cc.getPayment());
  9. System.out.println("Total Charges: " + cc.getTotalCharges());
  10. System.out.println("Total Payments " + cc.getTotalPayments());
  11.  
  12. System.out.println("\n");
  13. System.out.println("Transaction (0=Quit, +$=charge, -$=payment, 9999=Limit increase): ");
  14. transval = Console.in.readDouble();
  15. if (transval == 0){
  16. break;
  17. }
  18. if (transval == 9999){
  19. cc.creditIncrease();
  20. }
  21. if (transval > 0) {
  22. System.out.println("Transaction description: ");
  23. transdesc = Console.in.readLine();
  24. transdesc = Console.in.readLine();
  25. cc.setAmount(transval);
  26. cc.setDescription(transdesc);
  27. cc.Transaction();
  28.  
  29. } else if (transval < 0){
  30. cc.setAmount(transval);
  31. cc.setDescription("Payment");
  32. cc.setPayment(transval);
  33. cc.Transaction();
  34.  
  35. }
  36. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: while loop

 
0
  #2
Sep 22nd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 790
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: while loop

 
0
  #3
Sep 22nd, 2007
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
  1. transval=Console.in.readDouble();
Something like
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 238
Reputation: ceyesuma is an unknown quantity at this point 
Solved Threads: 0
ceyesuma ceyesuma is offline Offline
Posting Whiz in Training

Re: while loop

 
0
  #4
Sep 23rd, 2007
Originally Posted by darkagn View Post
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
  1. transval=Console.in.readDouble();
Something like
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: sb7000 is an unknown quantity at this point 
Solved Threads: 1
sb7000 sb7000 is offline Offline
Newbie Poster

Re: while loop

 
0
  #5
Nov 8th, 2007
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;
}
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC