I need help guys ... Im doing a program that ask the user to choose an option 1-4. Each option has its own task for option 1, the user needs to enter the number of US dollars" option 2 - the user needs to neter number of euros, option 3 the user enter number of yen and option 4 exits the program.
Here's my codes for this part:
Now i got all this but the problem is im not sure how to calculate the total. Whnever the usert chooses an option and enter the quantity, the quantity they enter will be added to the total until the user chooses 4 to exit. When the user exits out the program will print out the total savings and exit. The object that will keep track of the total amount of the user will be implement a GIFTS object..
Im very new in java, so plz can anybody help me with this..any hint , clue or suggestions..
author and iconoclast
Your variables "dollars", "yen", and "euros" are declared inside "if" blocks. A local variable isn't visible outside the block where it's declared, so there's no place in the program where you can access all the variables and sum then up. The solution to this problem is to move the declarations up to the top of the method, where you would probably want to initialize each one to zero. Then all the code throughout the method could access them.
Be careful, though: remember to account for what happens if the user enters Euros (for example) twice. Make sure you get the right answer! You may need to introduce more variables.
1. put a variable outside while loop, named savings - data type double and initialize its value with 0 2. in every if blocks, sum savings with each numbers, ex. in "if yen" block, after multiply the yen value, then add a line with 3. you can still access the savings variable, whenever it has come out the while loop. Example:
Joined: Mar 14, 2005
hello guys i foillwed ur instructions but im not getting the right output still..
i did this codes and whnever i tried to run it its just asking me the options and not totalling the savings...