|
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
|
|
|
|
|
You can see an example about it with socket search "Transfer file" on codeproject.
|
|
|
|
|
How do I pack two integer values in a double ?
i.e
<br />
int x=1000;<br />
int y=2000;<br />
<br />
double z;<br />
now I want the first four bytes to be occupied by x and the next 4 by y in Z
How do I do that? any shift operators would help? please tell me how do I pack & unpack it?
|
|
|
|
|
what about using union ?
union U {
double _d;
int _i[2];
};
|
|
|
|
|
Thank you for your reply sir, But I do not want an union The matter is,
You have a function like this. Imagine you cannot change it's params. It's built by someone and it's used in numerous instances.
<br />
void testDouble(double d)<br />
{<br />
cout<<d;<br />
}<br />
Now you say , testDouble(2143250); it prints 2143250. Now I want to send two integer values to this function for other reason. I have two numbres, 1000, 2000. these are ints so takes only 4 bytes.
<br />
double 00000000000000000000.....64<br />
now 0000000..32 | 0000.......32 is my idea.<br />
<br />
But how do I do that?
So that in the function, I can do like,
void testDouble(double d)
{
cout<<(HIGHER32)d;
cout<<(LOWER32)d;
}
get me now?
|
|
|
|
|
wait, you want to merge 2 ints into a double, or split a double into 2 ints ?
BTW be careful, sizeof(int) == 4 only on 32 bits plateforms !
|
|
|
|
|
|
int main(int argc, char* argv[])
{
__int32 i[2];
i[0] = 1000;
i[1] = 2000;
double d = 0;
d = *(double*)&i[0];
printf("%f\n", d);
__int32 *o;
o = (__int32*)&d;
printf("%d %d\n", o[0], o[1]);
return 0;
}
of course, anyone doing something like this would end up in the Daily WTF, for sure.
|
|
|
|
|
I'll test this & tell you. Thanks. BRB
|
|
|
|
|
Chris, that worked thanks. Now I'm happy I have a way. But if you can still get me a way that will never take part in WTFs that'd be excellent.
|
|
|
|
|
Is this what you are after:
int int
/-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-\
| | | | | | | | | | | | | | | | |
\-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-/
double
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
lol, David, are you moking at newbies ?
|
|
|
|
|
Moking? Do you mean mocking? No, I was just trying to clarify what the intent was by using a visual.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Moking? Do you mean mocking?
indeed i was.
but that's true also that pictures are more clear than words sometimes...
|
|
|
|
|
|
Hello members,
I have a VC++ 6 dialog based application as a stand alone exe which is called from a batch or a script file. How can I change the return code of my application to the operating system after closing my application? I want to check in the batch or script file, if the application worked fine or if an error has occured.
Hope anyone can help me.
Thanks
Juergen
|
|
|
|
|
your main() function must not be void if you want to return a value.
only then, you return the value you like, and knowing the meaning in the batch script, you can then catch it and test it...
|
|
|
|
|
Hello TOXCCT,
I do not a have a main(). I do have a WinMain() and this is somewhere in the installation directory of Visual C++ (I think in WinBase.h). This file is not (directly) part of my project.
|
|
|
|