Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Bubble sort help...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ruscutie




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Sat Nov 11, 2006 6:41 pm   Post subject: (No 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
ruscutie




PostPosted: Sat Nov 11, 2006 6:43 pm   Post subject: (No subject)

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




PostPosted: Sat Nov 11, 2006 7:01 pm   Post subject: (No 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.
Wolf_Destiny




PostPosted: 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.
ruscutie




PostPosted: Sat Nov 11, 2006 8:23 pm   Post subject: (No subject)

thanx guys... from next time i will compile it... Wink
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: