aspose file tools*
The moose likes Beginning Java and the fly likes counter help(summing up the totals) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

counter help(summing up the totals)

jc asuncion
Greenhorn

Joined: Nov 11, 2005
Posts: 1
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..

plzzz....thank u
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi,

Welcome to JavaRanch!

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.


[Jess in Action][AskingGoodQuestions]
Ricky Martaputra
Ranch Hand

Joined: Apr 04, 2005
Posts: 42
Hi,

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:
jayson clark
Greenhorn

Joined: Mar 14, 2005
Posts: 14
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...

what am i doing wrong?

plz help
 
wood burning stoves
 
subject: counter help(summing up the totals)