PDA

View Full Version : pseudocode help/challenge



Bazthemod
12th March 2006, 12:43 AM
Deep Fried, Kingsize Marsbar to the first person who can do me a massive favour by converting the following visual basic code into pseudocode.... c'mon techie peeps please help :I:clown:8):cool:

Ok its a simple lottery program that generates 7 random numbers and my teacher's off and im really stuck! :(

Dim list(7) As Integer


Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdClear_Click()
Picdisplay1.Cls
Picdisplay2.Cls
Label2 = ""
Label3 = ""
Label4 = ""
Label5 = ""
Label6 = ""
Label7 = ""
Label8 = ""
End Sub

Private Sub cmdGenerate_Click()
Randomize
For pick = 1 To 7
Number = Int((49 * Rnd) + 1)
If pick > 1 Then
For nums = 1 To pick
If list(nums) = Number Then
Do
Number = Int((49 * Rnd) + 1)
Loop Until Number <> list(nums)
End If
Next nums
End If
list(pick) = Number
Picdisplay1.Print list(pick)
Next pick
End Sub

Private Sub cmdSort_Click()
dummy = 0
For Value = 1 To 7
For check = (Value + 1) To 7
If list(Value) > list(check) Then
dummy = list(Value)
list(Value) = list(check)
list(check) = dummy
End If
Next check
Next Value

For Value = 1 To 7
Picdisplay2.Print list(Value)
Next Value

Label2 = list(1)
delay
Label3 = list(2)
delay
Label4 = list(3)
delay
Label5 = list(4)
delay
Label6 = list(5)
delay
Label7 = list(6)
delay
Label8 = list(7)

End Sub

Smitty
12th March 2006, 04:12 AM
What do u mean by pseudocode mate? Done a bit of VB, n understand that program so may b able to help!:)

AeroJonny
12th March 2006, 04:37 AM
Hm, C++ and a bit of matlab are about as far as i get, but good luck I'm sure some1 will be able 2 help u.

Bazthemod
12th March 2006, 05:08 AM
seemingly its meant to be done before you write the code and its a simplistic version of the code in english type words, but i dont have a clue where to start lol :D:I:clown:

3GGG
12th March 2006, 06:17 AM
It is a method of writing down in almost plain English what steps you would take to solve the problem. Then later you can code it in the programming language that you will use. In essence if the pseudocode is well enough written it should be fairly easy to then write the program in any programming language.

I actually find it harder to do the reverse, though it is a good and often necessary exercise if you have to translate one language like VB into C for example.

Try to think how you would generate 7 (random) numbers within a certain range and not one the same and display them and write the steps down and compare with the routines given and it will give you a start.

Hope that helps.

AndyP & Lenore
12th March 2006, 07:10 AM
I used to write games on my Commodore Vic 20 and Commodore 64 in BASIC back in the good old 80's and early 90's. But I doubt that will help.

duncan
12th March 2006, 07:15 AM
Heh. Basic.:D

10 PRINT "I rule"
20 GOTO 10

RUN ENTER

minidriver#1
12th March 2006, 09:01 AM
it'd help if you tell us what hte language is and also format the code as it should be written, so i can see the loops and function calls a bit clearer. I did C, C++ and Visual C at Uni along with some php and ASP and Visual Basic, and that looks a little like Visual Basic, but i'm not too hot on that.

minidriver#1
12th March 2006, 09:22 AM
ok here goes...

Create a array called List which is 7 characters long and an integer

Create/call a function called cmdExit_Click which will end the program when called
Create/call a function called cmdClear_Click which will call the picdisplay1 and picdisplay2 classes (presumably to display 2 picture objects), set labels 2 through 8 to empty strings.
Create/call cmsGenerate_Click

Call Randomize initialise VB's random number generator
While the number of random numbers to be selected is still between 1 and 7 choose a random number between 0 and 50 or 1 and 49 (not sure about that)
When a number is selected add it into the List array at first available array position, then increment Number so that next random number is placed into the next array slot
Display the number to screen(? or hidden object) in the Picdisplay1 object

begin checking that numbers are all different
select first number, assign it to variable dummy and compare to remaining numbers.
move to next number, assign it to variable dummy and compare to remaining numbers.
repeat for remaining numbers

Begin printing numbers to screen(? or hidden object) in Picdisplay2 object through numbers 1 to 7

Then set each label to hold the value for its corresponding number.
Label2 is set to number in position 1 of array List
Label3 is set to number in position 2 of array List
Label4 is set to number in position 3 of array List
Label5 is set to number in position 4 of array List
Label6 is set to number in position 5 of array List
Label7 is set to number in position 6 of array List
Label8 is set to number in position 7 of array List

End the process



Something along those lines. I forget what some bits of code do, but you should know and be able to modify that psuedocode to make more sense. Hope that helps though.

AndyP & Lenore
12th March 2006, 09:32 AM
quote:Originally posted by duncan

Heh. Basic.:D

10 PRINT "I rule"
20 GOTO 10

RUN ENTER


Something like that. But a tad more complex.

I even wrote a prgram that would tell you how much your cinema tickets were if you entered the number of Adults, Children etc. Very sad. But very complex for a 10 year old.:D

Gismo
12th March 2006, 06:29 PM
I'm with 3GGG on this one, it's a psuedocode, write it down as you would expect others to read it and to then turn it into the correct code if required ;)

3GGG
12th March 2006, 06:37 PM
Note from teacher: Actually I want to see a small improvement made to the example - The numbers chosen by the computer must equal the number in next week's lottery draw.

Bazthemod
12th March 2006, 09:40 PM
KJ Your the man ... that looks good to me :cool::D:cool:

Thank you so much; as promissed... :p

http://www.erin.utoronto.ca/~w3pkota/sabbatical_webpage/England/scotland.edinburgh.77.JPG

euan
13th March 2006, 01:26 AM
quote:Originally posted by Bazthemod

KJ Your the man ... that looks good to me :cool::D:cool:

Thank you so much; as promissed... :p

http://www.erin.utoronto.ca/~w3pkota/sabbatical_webpage/England/scotland.edinburgh.77.JPG


That's one of the most disgusting things I've seen on the web in ages! Looks horrid!

duncan
13th March 2006, 03:28 AM
quote:Originally posted by AndyP & Lenore

I even wrote a prgram that would tell you how much your cinema tickets were if you entered the number of Adults, Children etc. Very sad. But very complex for a 10 year old.:D


Quality:D

minidriver#1
15th March 2006, 08:52 AM
what the **** is that? a fried tongue? lol.

Burple
15th March 2006, 07:06 PM
quote:Originally posted by KJ_innit

what the **** is that? a fried tongue? lol.


lol...

Deep fried Jobbie??

nice... :blackeye::D:p