3 Replies - 472 Views - Last Post: 18 May 2010 - 10:14 AM Rate Topic: -----

#1 Xplode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-May 10

Need some help on this pseudocode please!

Posted 17 May 2010 - 05:53 PM

Hello, I am a newbie in programming and need help with a pseudo code, this is not homework I am just studying on it. Here is what I have so far

Design a while loop that generates random numbers while the numbers are greater than 0 and that counts how many random numbers are between 10 and 20 inclusively.

Start
Generate Number > 0
get Number
while Number 10-20
add 1 to count
endwhile
stop



I need something simple, would this work?

Is This A Good Question/Topic? 0
  • +

Replies To: Need some help on this pseudocode please!

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10479
  • View blog
  • Posts: 38,851
  • Joined: 27-December 08

Re: Need some help on this pseudocode please!

Posted 17 May 2010 - 09:27 PM

Not quite. Because you are supposed to design a loop to continue while rand > 0, you want the rand to be able to be < 0 at some point. Then, inside the loop, test the rand to see if it is between 10-20, then increment the counter if this is true.
Was This Post Helpful? 0
  • +
  • -

#3 Xplode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-May 10

Re: Need some help on this pseudocode please!

Posted 18 May 2010 - 10:10 AM

View Postmacosxnerd101, on 17 May 2010 - 08:27 PM, said:

Not quite. Because you are supposed to design a loop to continue while rand > 0, you want the rand to be able to be < 0 at some point. Then, inside the loop, test the rand to see if it is between 10-20, then increment the counter if this is true.



kk The loop should continue now if the number is > 0


Start
Generate Number
While Number > 0
check number
If number is between 10 and 20 then
+1 to counter
endwhile
stop

correct? or atleast on the correct path?

This post has been edited by Xplode: 18 May 2010 - 10:12 AM

Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10479
  • View blog
  • Posts: 38,851
  • Joined: 27-December 08

Re: Need some help on this pseudocode please!

Posted 18 May 2010 - 10:14 AM

You'll want to generate a new random in the loop to avoid an infinite loop. Otherwise, your algorithm looks a lot better.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1