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

#1 B2SALONWEBDESIGN   User is offline

  • New D.I.C Head

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


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.

// 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
Write “Enter number please: “
Input Number
While Number != 0
If Number > 0 Then
Set PositiveNumber = PositiveNumber + Number
Set NegativeNumber = NegativeNumber + Number
End If
End While
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
  • +


#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5226
  • View blog
  • Posts: 14,005
  • Joined: 18-April 07


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   User is offline

  • D.I.C Addict

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


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