|
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
|
|
|
|
|
it's not possible; as soon as you receive a new number the average will be modified, and since you cannot keep an history of the values already read, there is no way of determining what numbers that you already read that are above or below the average.
(unproven, and unverified )
The problem with the average is that you can have a new value that will completly "unbalance" the computed average, for example you have a series of values in the [1, 10] range, the average will be between those 2 values, but if at some point you have a very large value, it will mess the result, and statistically the result will not be valid, unless you can filter out those bad values.
( but I expect someone to come with a brilliant mathematical answer that will awe us )
|
|
|
|
|
I'm guessing recursion is your friend here, assuming a magic computer that'll never stack overflow
Pseudo-C-ish-code
above_average = 0;
void main()
{
doit(0,0)
print( above_average " of your numbers were above average )
}
int doit( int sum, int count )
{
print( "enter number, -1 to end" );
int input
get input from keyboard
int average;
if input == -1
{
average = sum/count
}
else
{
average = doit(sum+input, count+1)
if( input > average )
{
above_average++
}
}
return average
}
Now remember, your lecturer is probably reading these forums....
(Technically, this is using a stack, just not the kind of stack most people would think of!)
|
|
|
|
|
benjymous wrote: (Technically, this is using a stack, just not the kind of stack most people would think of!)
Declaring variables and calling functions would violate the "no stack" requirement! Nice solution, BTW.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Hello guys,I'm Pardi Banjarnahor. I come from Indonesia.
If you don't mind, I want to ask you for help. Now, i want to create (make) a "client-server Program" with visual C++ 6.0.
That program should able act as a client or severt. either as a client/server, it should be possible to send data from client to server, and viceversa.
If you are one who used to programming visual C++ or can give me some advice or help, I'm so grateful if you would do that.
Thank You Very Much
Pardi
N.B: Please Help Me, I'm so very in need abput client-server application with visual c++.
you can directly cantact me through e-mail: pardibanjarnahor@yahoo.com
Thanks and GBU
|
|
|
|
|
Pardi Banjarnahor wrote: i want to create (make) a "client-server Program" with visual C++ 6.0.
What type of application do you want to create?
Pardi Banjarnahor wrote: me some advice or help
If it's a MFC based application...
You can use CSocket/CAsyncSocket clases to create a client/server application.
You can find a lot of articles on codeproject for doing the same.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Here are two articles on code project, that might be of your interest.
Article-1[^]
Article-2[^]
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|