Computer Science Canada

Bubble sort help...

Author:  ruscutie [ Sat Nov 11, 2006 4:04 pm ]
Post subject:  Bubble sort help...

hey i'm making this code in which computer picks random numbers and then it gives the user options. one of the options is to sort the even numbers and the odd numbers. i have to do this using bubble sort and "procedure". My code is not working... this is the code

code:
var num : array 1 .. 10 of int
var temp, answer : int

var odd, even : array 1 .. 10 of int
var oddcount, evencount : int := 0

procedure pick
    randomize
    for i : 1 .. 10
        randint (num (i), 10, 99)
        put num (i)
        delay (50)
    end for
end pick

procedure second

    put "The sorted list is"
    for i : 1 .. 10
        put num (i)
        for i : 1 .. evencount
            put even (i)
            if num (i) mod 2 = 0 then
                evencount := evencount + 1
                even (evencount) := num (i)
                even (evencount) := num (i)
            end if
        end for
        put "The even numbers are", evencount
    end second

    procedure menu
        pick
        put "1..no repeating"
        put "2..odd and even"
        put "3..large to small"
        put "4..median"
        get answer
        if answer = 2 then
            second
        end if
    end menu
    menu

Author:  Ultrahex [ Sat Nov 11, 2006 6:41 pm ]
Post subject: 

Remeber First to put your code in BBCODE Tags so its more easy readable, ontop of that your code does not compile... which is a big issue; you probably want it at least compiling before asking for help.

Peace
Ultrahex

Author:  ruscutie [ Sat Nov 11, 2006 6:43 pm ]
Post subject: 

i don't understand compiling like wat do u mean by "compile"? Embarassed

Author:  [Gandalf] [ Sat Nov 11, 2006 7:01 pm ]
Post subject: 

Compling is turning your text program into an executable which you then run. So Ultrahex was saying that you should at least make your program run, even if it is wrong, before asking for help.

I'm pretty sure that's because you're missing an "end for" somewhere in there.

Author:  Wolf_Destiny [ Sat Nov 11, 2006 7:57 pm ]
Post subject:  Re: Bubble sort help...

ruscutie wrote:

code:
procedure second

    put "The sorted list is"
    for i : 1 .. 10
        put num (i)
        for i : 1 .. evencount
            put even (i)
            if num (i) mod 2 = 0 then
                evencount := evencount + 1
                even (evencount) := num (i)
                even (evencount) := num (i)
            end if
        end for
        put "The even numbers are", evencount
    end second


here's the broken bit of code. Now what are some problems? *cough*for loops*cough*

You've used the identifier "i" twice, and you're missing an end for. As Ultrahex said, you should make sure your code can run before posting it here asking for help. Unless of course the problem is that you don't know why it won't run. But with such short code it shouldn't be too big a problem.

Author:  ruscutie [ Sat Nov 11, 2006 8:23 pm ]
Post subject: 

thanx guys... from next time i will compile it... Wink


: