# MODULES AND PSEUDOCODE

Page 1 of 1

## 2 Replies - 14938 Views - Last Post: 08 March 2011 - 03:48 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=219595&amp;s=9f23a2f029a19ca15c43e22f2b18eb10&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 B2SALONWEBDESIGN

Reputation: 0
• Posts: 8
• Joined: 26-January 11

# MODULES AND PSEUDOCODE

Posted 01 March 2011 - 08:30 AM

Hello... It is me again. Please tell me if I am lost or on right track where these two problems are concerned. Thanks, this site has been a tremdous help thus far... excellent community.

1. Write a program segment that stimulates rolling a die 50 times by generating and displaying 50 random integers in the range of 1 to 6.

Declare Die1 as Integer
Declare Num as Integer
For (Num = 1; Num <= 50; Num++)
Set Die1 = Floor(Random * 6) + 1
End For
Write “50 Random Numbers are: “ + Die1

2. For a list of numbers entered by the user and terminated by 0, find the sum of positive numbers and the sum of negative numbers.

MAIN MODULE
// This program displays the sum of both positive numbers and negative numbers entered.
// Written by Brett Bell
Declare Number as Integer
Declare PositiveNumber as Integer
Declare NegativeNumber as Integer
Call Input Module
Call Calculations Module
Call Output Module
End Program
INPUT MODULE
Input Number
CALCULATIONS MODULE
While Number != 0
If Number > 0 Then
Set PositiveNumber = PositiveNumber + Number
Else
Set NegativeNumber = NegativeNumber + Number
End If
End While
OUTPUT MODULE
Write “The sum of all positive numbers is: “ + PositiveNumber
Write “The sum of all negative numbers is: “ + NegativeNumber

Is This A Good Question/Topic? 0

## Replies To: MODULES AND PSEUDOCODE

### #2 Martyr2

• Programming Theoretician

Reputation: 5186
• Posts: 13,916
• Joined: 18-April 07

## Re: MODULES AND PSEUDOCODE

Posted 02 March 2011 - 03:22 PM

You have a couple issues in both of these...

1) Remember to keep pseudocode English like in nature, the for statement looks pretty programmerish. That wouldn't be the structure if I was doing this in VB or Ruby. Which I should be able to do just from reading the pseudocode. Also, you want to be printing in the for loop the value of Die1 OR you want to be appending the value onto Die1 for display later. Right now you have it setup so that Die1 is getting overwritten each time and the result is that Die1 will display the last value rolled, not all values rolled.

2) Keep in mind that you have to keep prompting for a number in your while loop. As you have it now Number will never end up being changed and you will get stuck in an infinite loop. Re-prompt for another number and store it into "Number" after you have tested if it is positive or negative.

Other than that, not too bad.

### #3 ForcedSterilizationsForAll

Reputation: 33
• Posts: 506
• Joined: 16-July 09

## Re: MODULES AND PSEUDOCODE

Posted 08 March 2011 - 03:48 PM

for number 2 you should probably have something like

get number
Loop while number <> 0
do calculation
get number
end loop
display output

If it is suppose to display the calculations after every time you'll want to move the output display into the loop.