# pseudo-code (modular program)



## nova2177 (Jul 13, 2008)

have an pseudo-code assignment to finish but i am stuck on how to get a module from the pseudo-code that i have written, i have never done anything about module more than what it means. i don't know if anyone can show me from this example. don't worry this is not the assignment i got.

sum integer
num integer
count integer
sum := 0
count := 0
dowhile count < 3
println "enter num: "
read num 
sum := sum + num
count := count + 1
enddo
println "average = " sum/count

is there any way this can be divided into module(s), or you can show me any other examples thanks much.


----------



## jamiemac2005 (Jul 5, 2007)

Hey, i don't see anything here which needs to be modular... I believe the meaning for module is a block of code which may be re-used... e.g. how we use functions/procedures rather than re-writing code millions of times... Or the same for Iteration statements, we use them to re-run a block of code(module) a number of times...

A good example would be an output routine like outputting the state of a few variables at any one time, usually i'd expect to see something like :
(I don't know the notation you use for modules/procedures etc)


```
...
procedure outputStateOfVars;
begin
  println sum
  println count
end

(here you would mess with the variables)
sum := 1 
count := 1
(then output them)
outputStateOfvars;
(then mess with them some more)
sum := count+5;
(then output them again)
outputStateOfVars;
```
Anyway theres a definition here: http://en.wikipedia.org/wiki/Modularity_(programming)
(Wiki is a good resource no-matter what the news says)

which kind of sums it up, we use modules to make code more easily maintainable and to allow code re-use.

If you need more help then post back with your queries, to be honest it's hard for me to explain modularity because it's just something that's a constant in my mind.


----------

