Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Finding average
PostPosted: February 17th, 2012, 6:51 pm 
BANNED
Offline

Joined: November 19th, 2011, 5:37 pm
Posts: 258 us
RS Name: firering401
RS Status: F2P
I'm not really sure what the best way of finding the average for a user input box would be. I have had some concerns.

- You don't know how many numbers (or in this case grades) the user will enter, so you don't know what to divide by
- I'm not sure how to incorporate something as complicated as that in a simple program.

The program I am referring to is a simple calculator I wrote to get the hang of UI + Integer.parseInt. I would like to have the user calculate the average within the script.

I am referring to this

http://pastie.org/3405256


Any pointers/tips in the right direction would be greatly appreciated. Thanks :D


Top
 Profile  
 
 Post subject: Register and login to get these in-post ads to disappear
PostPosted: February 17th, 2012, 6:51 pm 
BANNED

Joined: September 9th, 2004, 1:47am
Posts: 9047
Location: In your web browserz


Top
  
 
 Post subject: Re: Finding average
PostPosted: February 17th, 2012, 7:24 pm 
Dragon Member
Offline

Joined: May 13th, 2005, 7:51 pm
Posts: 3099
Location: Arizona us
RS Name: Evalithia
RS Status: P2P
Use an indefinite loop. Loop the statement that asks the user for grades until the user personally terminates the loop, then go on to find the average.
Have an incrementing variable to count the number of entries.

for example, in pseudocode

Code:
i = 1
numEntries = 0
input = 0
while i == 1
{
if input != "done"
{
ask the user to input values, and type in "done" when they have all the values
}
else
{
i = 2; //set i to two so the loop terminates
}
numEntries = numEntries + 1 //increment a value, this will be how many entries there are
}

_________________
Image
2014.3.28
[size=70]Steam


Last edited by Evelyn on February 17th, 2012, 7:32 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Finding average
PostPosted: February 17th, 2012, 7:27 pm 
Runite Member
User avatar
Offline

Joined: January 4th, 2008, 9:33 pm
Posts: 749
Location: Oregon us
RS Name: Parselmouth
RS Status: P2P
Clan Name: DGS
How are you planning on getting any input from the user? Are you taking it all in via the command line?

_________________
Image

RSN: Parselmouth | Jaysawn on ********


Top
 Profile  
 
 Post subject: Re: Finding average
PostPosted: February 18th, 2012, 7:00 am 
BANNED
Offline

Joined: November 19th, 2011, 5:37 pm
Posts: 258 us
RS Name: firering401
RS Status: F2P
Jason wrote:
How are you planning on getting any input from the user? Are you taking it all in via the command line?



this is based on user input using JOptionPane (my book goes into depth on JOptionPane but only /barely/ touches the throws IOException user input).


Top
 Profile  
 
Display posts from previous:  Sort by  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to: