Computing.Net > Forums > Programming > Pseudocode Explanation

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Pseudocode Explanation

Reply to Message Icon

Name: DipsyGirl
Date: June 14, 2005 at 06:54:23 Pacific
OS: XP Home
CPU/Ram: 1 G
Comment:

Algorithm

Declare count As Integer

Control
Declare num As Integer
Declare total As Integer
Declare avg As Real
count = 0
total = 0
num = 90
avg = Process AvgSoFar( total, num )
num = 95
avg = Process AvgSoFar( total, num )
Print “num = ” + num
Print “total = ” + total
Print “count = ” + count
Print “avg = ” + avg
End

AvgSoFar( sum As Integer&,
val As Integer )As Real
Declare answer As Real
count = count + 1
val = val + 5
sum = sum + val
answer = sum / count
Return answer

OK, I understand which are global and local variables and the call-by-value and call-by-reference for the AvgSoFar module. What I don't understand is how to work the num variable so that the total and num (for Process AvgSoFar) are inserted for val and sum and how the answer returns. It is my understanding the answer returns to avg value. However, I cannot make sense of the total being the value for sum when the original total value is 0 ... not to mention I haven't a clue about what is counted. Can anyone explain the workings of this and supply the variable values with explanation?

I'm learning.



Sponsored Link
Ads by Google

Response Number 1
Name: mdow
Date: June 14, 2005 at 07:36:01 Pacific
Reply:

You have:
count = 0
total = 0
num = 90
avg = Process AvgSoFar( total, num )
which is the same as:
avg = Process AvgSoFar( 0, 90 )

the function AvgSoFar takes 0 as sum and 90 as val therefore, sum now = 0 and val now = 90.

add 1 to count
add 5 to val
add val to sum

count = 1
val = 95
sum = 95

answer = (sum / count) = (95/1) = 95

avg = answer (answer is the result of the function)

Then the function is called again

Hope this helps
--Mike


0

Response Number 2
Name: DipsyGirl
Date: June 14, 2005 at 08:47:33 Pacific
Reply:

I thought I was doing it right. It just made no sense to me to not return and continue recalculating. I suspect I was trying to make this simple bit far more complicated, LOL. Thank you for being my second brain!

I'm learning.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


MSVC++ 6.0 Compiler help file



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Pseudocode Explanation

pseudocode help www.computing.net/answers/programming/pseudocode-help/3933.html

Pseudocode (small program) www.computing.net/answers/programming/pseudocode-small-program/11153.html

Where are the programers www.computing.net/answers/programming/where-are-the-programers-/13586.html