Computer Science Canada average help |
Author: | ruscutie [ Thu Jan 25, 2007 11:04 pm ] | ||
Post subject: | average help | ||
hi, i have to take out the average (mean) of 20 numbers...soo first i have to ask the users to enter the numbers..
here is the code... the user can enter the numbers using the code but i can't think of a method to find the average (mean)...plzz help |
Author: | apomb [ Thu Jan 25, 2007 11:13 pm ] |
Post subject: | Re: average help |
Simply add the numbers up, and divide by the number of numbers entered :/ this is basic, and i mean BASIC math... what grade ye be in? |
Author: | ruscutie [ Thu Jan 25, 2007 11:16 pm ] |
Post subject: | RE:average help |
i know... but that makez the program 2 long... i'm preparing 4 my exam and my teacher told us 2 use for i... but i'm stuck and can't think of how do u add them... |
Author: | apomb [ Thu Jan 25, 2007 11:39 pm ] |
Post subject: | Re: average help |
hmm ... adding a successive number of numbers? which are already in an array? ... something about having a total coems to mind, however. ![]() |
Author: | agnivohneb [ Thu Jan 25, 2007 11:41 pm ] | ||
Post subject: | Re: average help | ||
You can try
|
Author: | apomb [ Thu Jan 25, 2007 11:47 pm ] |
Post subject: | Re: average help |
damnit man ... dont just give the code away like that ... ruscutie was on the right track. im sure they could have figured it out eventually ... its people like you who make this website a haven for people who hijack any code they see and pass it off as their own. please, respect the rules, and dont give in and just supply code . especially when its such an easy, yet important thing to learn, now, whoever asks for help is just going to use that code, and not know whats happening; the least you could have done was comment your code, so the person asking for help knows what the code is doing. jeeze |
Author: | ruscutie [ Fri Jan 26, 2007 12:07 am ] |
Post subject: | RE:average help |
can some1 plz explain to me what is [upper]... it was used in the code above...? |
Author: | agnivohneb [ Fri Jan 26, 2007 12:20 am ] |
Post subject: | RE:average help |
Sry CompWiz333. |
Author: | apomb [ Fri Jan 26, 2007 12:20 am ] |
Post subject: | Re: average help |
that grabs the largest number in the array num, which, actually is incorrect, and should actually be changed, so that mean is divided by 20, not the largest number in the array. on a side note, Im concerned for your mark on this exam, ruscutie ... and dont apologize to me, agnivohneb though i do thank you for apologizing. |
Author: | agnivohneb [ Fri Jan 26, 2007 12:24 am ] |
Post subject: | RE:average help |
Upper is the same thing as saying 20. in that code num is an array of 1 to 20. upper gets the highest number in the array (20) and uses it. there is also lower which dose the opposite. |
Author: | apomb [ Fri Jan 26, 2007 12:30 am ] |
Post subject: | Re: average help |
but thats not whats in the array, since the user is entering the numbers, it will pick the highest number entered, which is very unlikely to be 20. |
Author: | ruscutie [ Fri Jan 26, 2007 12:38 am ] |
Post subject: | RE:average help |
thnx guyz |
Author: | apomb [ Fri Jan 26, 2007 1:35 am ] |
Post subject: | Re: average help |
y'r wlcm |
Author: | Bored [ Fri Jan 26, 2007 12:32 pm ] | ||
Post subject: | Re: average help | ||
CompWiz333 @ Fri Jan 26, 2007 12:30 am wrote: but thats not whats in the array, since the user is entering the numbers, it will pick the highest number entered, which is very unlikely to be 20.
compwiz, I'm afraid your wrong here. upper gets the upper bound in the array. That is not the largest number stored but the index of the upper element. For example:
Notice how upper returns the upper bound of the array and not the highest value, and lower the lower bound and not the lowest value. Go ahead try it yourself. |
Author: | BenLi [ Fri Jan 26, 2007 1:26 pm ] |
Post subject: | RE:average help |
thats not wha he means. Take this for example array 10..20. There are only 10 elements in the array, yet the upper function would return 20. Because turing arrays do not start at a default value of 1 or 0, the upper function does not accurate reflect how many elements of the array there are |
Author: | apomb [ Fri Jan 26, 2007 3:21 pm ] |
Post subject: | Re: average help |
I dont program in Turing, im my understanding of agnivohneb wrote: in that code num is an array of 1 to 20. upper gets the highest number in the array (20) and uses it. there is also lower which dose the opposite.
was that it indeed got the highest number in the array. Thank you for pointing out what upper actually does, Bored. |
Author: | Bored [ Fri Jan 26, 2007 4:32 pm ] |
Post subject: | Re: RE:average help |
BenLi @ Fri Jan 26, 2007 1:26 pm wrote: thats not wha he means. Take this for example array 10..20. There are only 10 elements in the array, yet the upper function would return 20. Because turing arrays do not start at a default value of 1 or 0, the upper function does not accurate reflect how many elements of the array there are
In this situation however, upper will return the size of the array as the array starts on 1. In other istuations the size of the array can easily be found using the formula, size = upper (array) - lower (array) + 1 |