int averege4( int a , int b , int c , int d ) { return ( averege3 ( a , b , c ) + d) / 2; }
int averege3( int a , int b , int c ) { return ( averege2 ( a , b ) + c) / 2; }
int averege2( int a , int b ) { return ( averege1 ( a ) + b) / 2; }
int averege1( int a ) { return ( 0 + a / 2 ); }
why do the result is wrong?
Have you worked through it by hand?
Have you stepped through it in the simulator?
Interesting, what is your fixation with dividing by 2?
You need to understand some basic concepts of maths before trying programing.
There are filter solutions where new and old samples gets different weight instead of just taking the average of the samples. But your code does not seem to produce any meaningful result.
If I have the values 10,10,10 and 10, I would expect the average to be 10. Can you honestly say that your code produces that result?
This is not a computer science problem. This is a very, very, basic math problem from junior days in school.
Just a followup - have you recently looked at recursive functions? Are you sure this is a problem that is best solved by some form of recursive-descent solution?
it works now. you must put in a program called main and call averege4 from there.
You mean a function called main().
No. Your program does not seem to work - at least not if you want it to produce the average of 1, 2, 3 or 4 values.
Next thing - how can you claim "why do the result is wrong?" if your original attempt didn't even have any main()? Your original program couldn't even produce any result at all without a main().
why did you assume i needed average. i did not say average anywhere. i said averege everywhere!
and the result was wrong. i got error. error is not right. it is wrong.
and i did make a program called main. it had a function called main() in it.
i think i will now get 100% for my assignment. i will put in your comments to prove i got no help. because you people did not help AT ALL!
why did you assume i needed average
so, you do not need average, but you need averege
what is 'averege'
Erik
averege is the name i use for the function.
If every citizen of Farawayistan wrote perfect English nobody would have thought averege ment average.
i will put in your comments to prove i got no help. because you people did not help AT ALL! so, go ahead and stamp your little feet in the floor and, next time, use a name that does not seem like a misspelling of a common term.
yes sir.
next time i will be sure to use the names idoit and stoopid and bighed :)
but i dont stamp my feet. i am happy because i have good working code.