This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am having problems with this while loop when exiting. First I can enter valid info, when I want to exit I have to place a #1 in the share price JOptionPane and then a -1 to quit in the number of shares JOptionPane if I want to get any kind of a summary report. When I do this the number of shares are correct, number of transactions are correct, but the calculation of final pay due which is $100 base pay plus commission over $40 and commission over $40 is incorrect. I feel like I am in a loop, Please help. Bob
[ edited to preserve formatting using the [code] and [/code] UBB tags, and to remove the evil tab characters -ds ] [ May 06, 2004: Message edited by: Dirk Schreckmann ]
Using a local variable in the condition statement in the while loop is awkward since the "-1" alters it and thus your data that uses its value. Another possibility is to make up a boolean such as enterMoreData and ask the user to validate it, ie, have them enter something special to exit, during each loop. If you get the signal to stop at the bottom all you need to do is set the boolean value to false. The next round evaluates to false and you're out of the loop. If you do the asking and checking/validating at the top of the loop you can use "break" to exit the loop and process your data.