Runescape Bits & Bytes https://www.rsbandb.com/forums/ |
|
Finding average https://www.rsbandb.com/forums/viewtopic.php?f=38&t=82783 |
Page 1 of 1 |
Author: | Ring [ February 17th, 2012, 6:51 pm ] |
Post subject: | Finding average |
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 ![]() |
Author: | Adbot [ February 17th, 2012, 6:51 pm ] |
Post subject: | Register and login to get these in-post ads to disappear |
Author: | Evelyn [ February 17th, 2012, 7:24 pm ] |
Post subject: | Re: Finding average |
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 } |
Author: | Jason [ February 17th, 2012, 7:27 pm ] |
Post subject: | Re: Finding average |
How are you planning on getting any input from the user? Are you taking it all in via the command line? |
Author: | Ring [ February 18th, 2012, 7:00 am ] |
Post subject: | Re: Finding average |
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). |
Page 1 of 1 | All times are UTC - 7 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |