This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

validate before exit

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a program that takes user input of dollars, euros, and yen. Converts the yen and euros to dollars, keeps a running total and prints the total when the user chooses to exit program. The following program works fine except when I choose to exit the program it does not give me the total of all of the amounts that were entered. It only gives me the amount of the last input. Can someone give me a clue about what I am doing wrong?


[ March 25, 2006: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67528
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"WARRIOR ONE",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
Content minimized. Click to view
 
Sheriff
Posts: 9103
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It seems to work ok for me. 1.0 + 1.24 + 0.0092 = 2.2492

What were you expecting?
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first, you should switch the statement not 50 million if statements, it would clean up your code a lot.

and have a count in the loop that adds the converted number of dollars to count again until they quit the program,

and do/while loop to be precise..

i think this will help...

and remember to set count =0.
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bob,

How many sites are you planning on posting this into? You got help in two threads for this same code this morning on the Sun forums and now here as well.
 
BOB SMITH
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's good to get different ideas on how to write the best programs. As you notice different programmers have different ways of writing programs that produce the same result.
 
reply
    Bookmark Topic Watch Topic
  • New Topic