The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Pro32 on April 01, 2005, 09:22:49 PM

Title: average of number
Post by: Pro32 on April 01, 2005, 09:22:49 PM
I'm trying to find the average of the numbers inputed by the user. For example the user inputs: 23, 23, 4, 6.
I want to add them and than divide by the number of times inputed which is 4. Is there a procedure I can call to do this quickly or would I have to write an addition and division algorithm for it. Any hints are welcome.
Title: Re: average of number
Post by: sluggy on April 01, 2005, 10:33:17 PM
This sounds like homework or class assignment.....

You will have to write your own code, there is no API functions for this. And i wouldn't recommend any particular library functions for it either, because if you use those then you are not learning how to take input, treat ASCII as numbers, manipulate it, convert it back to ASCII, and output it.

Check the documentation that comes with your MASM32 install, there are macros that convert ASCII to numbers and back again. But you really should study the macros and understand what they are doing before you use them, as macros are expanded out at compile time, and if your tutor disassembles your code he may want to ask you what is happening  :U
Title: Re: average of number
Post by: hutch-- on April 01, 2005, 11:50:37 PM
hmmmm,

This does sound like homework. If you need help with assembler questions feel free to post them in here but don't post homework questions or we will remove them and your membership with it.
Title: Re: average of number
Post by: Pro32 on April 02, 2005, 12:50:16 AM
No this is not homework. If you look at my other post, I have already finished my calculator program. This is just out of mere interest.
Title: Re: average of number
Post by: sluggy on April 02, 2005, 02:11:52 AM
Quote from: Pro32 on April 02, 2005, 12:50:16 AM
No this is not homework. If you look at my other post, I have already finished my calculator program. This is just out of mere interest.
Okay, but you really should post code, or make your questions more specific  :8)
Title: Re: average of number
Post by: hutch-- on April 02, 2005, 08:39:48 AM
OK, the adds are the easy part but if you want any real precision, you will do all of this stuff in 80 bit floating point. Have a good look at Ray Filiatreault's FP tutorial as it has the technical data you need to get the required precision.
Title: Re: average of number
Post by: Tedd on April 02, 2005, 10:48:40 AM
As you're adding the numbers up, keep count of how many numbers you've added.
Then once you're done, use DIV with the count_of_numberrs_added.
Title: Re: average of number
Post by: Pro32 on April 02, 2005, 06:00:43 PM
ok thanks for the help. I'll see what I can do. I'll post code as soon as I tweak it.