Move the code that gets the price of the entered item (post#16) INSIDE the loop so it follows the code that gets the item number from the users.
Type: Posts; User: Norm
Move the code that gets the price of the entered item (post#16) INSIDE the loop so it follows the code that gets the item number from the users.
Where do you add the price of the item to the total?
If you want the add more prices to the total, you need to have code to do that after the item number is entered.
What does the code inside the while loop do?
Where do you add the price of the item to the total?
If you want the add more prices to the total, you need to have code to do that after the item...
Can you post the full code that shows where the above bit of code is executed?
@javaiscool Please do not do OPs work for him.
See: http://www.javaprogrammingforums.com/cafe/9544-problem-spoon-feeding.html
See the tutorial:
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
or ask google
or Search here on the forum
Do you know how to use arrays?
Make an array with the prices such that using the product number as the index gets the price.
That depends on what the code does with the data:
To count the number of items:
counter++; // add one to count of items
or to total their values:
total = total + thisItem; // add the value of...
That depends on what you want the loop to do and how many times you want to loop.
The for loop is used mainly when you know how many times you want to loop. Like when going through the contents of...