• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Help with Min, Max, and Average

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I would love if anybody could please help me with coding the math part of Min Max and Avg. I am having a difficult time trying to call to my variables to get the correct answer.
here is my code so far...


Also, I cannot get my loop to stop for my avg. it says infinity. lol
 
Greenhorn
Posts: 19
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where do you increment your count variable?

Edit: Nevermind I see it. Try moving your count++ outside of your assignment for Avg.

Count++
Avg = Num+Num/Count

Edit: Also take into consideration order of operations. You want to add the two numbers before you divide by the count so:

Count++
Avg = (Num+Num)/Count
 
Angela Hill
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my updated code. However when I put in an input say 1 2 3. my output is:Please enter your numbers.
1 2 3
The Average value is: 1.0
Maximum: 1
Minimum: 0
which is obviously not correct.

 
Daryl Cofer
Greenhorn
Posts: 19
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


That should do it. All I did was add a while loop that checks to see if there are any more tokens to look through.
 
Angela Hill
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much!!!
One last thing when I do the input the min comes out as 0 every time any suggestions to prevent this?
 
Daryl Cofer
Greenhorn
Posts: 19
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change the values when you initialize your min and max values.

Integer.MAX_VALUE and MIN_VALUE are built-in Java constants. They are the largest and smallest values that can be represented in integer form. So by setting the Max to Integer.MIN_VALUE, any number you enter is automatically going to re-assign the Max variable. Same goes with the Min variable.

 
Angela Hill
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah you are a saint I would have never of thought of that...then again i'm pretty new at all this lol Thanks again
 
Daryl Cofer
Greenhorn
Posts: 19
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Happy to help!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic