|
i'd say "no, not possible".
|
|
|
|
|
while number received != -1
store the number
end while
calculate the average
iterate through the array constructed below
if number in the iteration is above the average
increment counter
end if
end iterations
but the question is, WHY don't you want to use the STL ??
managing your own memory with such growing arrays are not good things to do by yourself...
|
|
|
|
|
While you can certainly compute the average without any additional storage, you'd still need to be able to go back through the set of numbers to pick out those greater than the average.
Just for our edificaton, why the restriction?
Is this your post, too?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
toxcct wrote: iterate through the array
you can't use arrays
|
|
|
|
|
|
why does that matter?
the original post said "no arrays".
|
|
|
|
|
because even if "iterate" is not the correct word, he can still traverse the array he'd have built...
|
|
|
|
|
he said 'no arrays' which I think means no arrays not iterators
cje
|
|
|
|
|
sorry, don't get you...
|
|
|
|
|
You just can't use arrays!
You have no array at the beggining, the user writes for you the input number by number-NO ARRAYS!
SnaidiS(Semion)
|
|
|
|
|
WTF !!
even if you had a console program, by which the user typed all the values in a single line, you could still create an array (or an STL container), parse the string to extract the values, and store them then...
if you don't explain your problem exactly, how can we guess what you're doing ?
|
|
|
|
|
the problem says that you mustn't use arrays or other allocation of memory.
SnaidiS(Semion)
|
|
|
|
|
then, no chance to resolve it
|
|
|
|
|
You say that there is no chanse to resolve it so can you prove it mathematiclly?
SnaidiS(Semion)
|
|
|
|
|
i'm tired with your thread... go find someone else to bore
|
|
|
|
|
Do you have any idea about it?
|
|
|
|
|
toxcct wrote: store the number
To what?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
to the paper next to the keyboard...
|
|
|
|
|
That'll work! It satisfies the requirements of not using a list, array, etc.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
So what kind of storage are you allowed to use?
|
|
|
|
|
just variables. int, float,char..
SnaidiS(Semion)
|
|
|
|
|
Can't you keep a running total and the number of inputs in two variables. Then you can calculate the average and of course half the number of variables is above the average. Or am I missing something?
led mike
|
|
|
|
|
missing something
calculating the average "on the run" is easy to do with a float and an integer.
but to tell how many of the inputs were upper than the average... no chance if you don't store the datas...
|
|
|
|
|
|
led mike wrote: ...of course half the number of variables is above the average. Or am I missing something?
That outliers can skew things quite a bit. Given the set {1, 2, 5, 7, 10, 18}, the average is 7.1. Four numbers in the set are below this, and two numbers are above.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|