2 Replies - 5678 Views - Last Post: 08 March 2011 - 03:48 PM Rate Topic: -----

#1 B2SALONWEBDESIGN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Write “Enter number please: “
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  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4359
  • View blog
  • Posts: 12,176
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 ForcedSterilizationsForAll  Icon User is offline

  • D.I.C Addict

Reputation: 33
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1