# PseudoCode Help for A Newbie

Page 1 of 1

## 1 Replies - 5226 Views - Last Post: 23 April 2005 - 10:29 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=10955&amp;s=4be449bc6ccc4e978009309ae516bf0b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 meow

Reputation: 0
• Posts: 1
• Joined: 23-April 05

# PseudoCode Help for A Newbie

Posted 23 April 2005 - 04:51 PM

Hi to all

I have just joined this lovely community today. I was wondering if someone would be willing to help out a newbie gal with a pseudocode problem....

Basically I am trying to write some pseudo code for the following problem

- A company has some data for each month for five years which = 60 integers
(12 integers for each year)
- A program must prompt the user to input the data and warn if the data is not an integer
- The program must calculate the average for each year and display it for each year (e.g. year 1, year 2, year 3, year 4, year5)

I have come with the following but am not sure if it's correct - I can see 2 flaws

1. There are 5 wasteful loops which capture virtually the same information
2. Also I feel that perhaps I should use an array to store the 60 integers

begin
Integer i, yr1, yr2, yr3, yr4, yr5

// Loop to get values of Year 1
i=1
REPEAT

Display “Enter values for Year 1 as integers”
IF value = integer THEN
Display “Confirm data entry finished”

ELSE
Display “Values entered not integers, re-enter as integers”

END IF

i = i+1

UNTIL (i<12)

// The value Yr 1 is equal to the sum of the values of all the months for Year 1
Yr1 = sum of i1+i2+ i3 +i4+i5+i6+i7+i8+i9+i10+i11+i12

// Call procedure to calculate average for Year 1, procedure is at end of program

Call Average (yr1)

Display “Average growth for Year 1 is” + Average

end

begin

// The program continues with another 4 loops same as the one above to capture the data for each year.
// I didn't include the four other loops in my example because I thought that this is a lot of repitition

________________________________________________________
Procedure to calculate Average for each year

begin
AVERAGE (integer yr)
AVERAGE = yr/12
end

Any advice would be very much appreciated.

Cheers

Meow

Is This A Good Question/Topic? 0

## Replies To: PseudoCode Help for A Newbie

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: PseudoCode Help for A Newbie

Posted 23 April 2005 - 10:29 PM

One way to optimize the procedure would be to run the whole program as a loop...assuming the program is going to prompt the user for the values for each year separately, you could do something like the following:
```Do until counter1 = 6
Do until counter2 = 12
Get information from user
Loop
Display information for current year
Loop

```

The idea would be to basically wrap your code inside another loop that runs 6 times.

Your idea of an array is a good one, although you'd really only need one array of 12 items, as you could reuse it through the loop. An even more optimized idea would be to use a single integer variable, adding the value of each entry to it through the inner loop, then dividing by 12 and displaying, then clearing the variable before the next loop.