Thread: noob question

  1. #16
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    Quote Originally Posted by QuantumPete View Post
    With code this simple and no machine-dependent operations, it's almost *always* the code

    QuantumPete
    I compiled the one where i "fixed" it and it still had some errors. I just fixed them all now and it compiles.

  2. #17
    Registered User
    Join Date
    Sep 2007
    Posts
    26
    yo!

    things are looking up. all the errors are gone but two:

    [linker error] undefined reference to 'randn' // i think this has something to do with the include statements at the begginging//

    and

    id returned 1 exit status.

  3. #18
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    Check the one i posted again. I changed the rand() thing.
    That error is actually nothing to do with the include files. It means the code for randn cannot be found (its probably from some lib you need to link). This error shoudnt occur if you use the one i posted.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by gillypie View Post
    yo!

    things are looking up. all the errors are gone but two:

    [linker error] undefined reference to 'randn' // i think this has something to do with the include statements at the begginging//

    and

    id returned 1 exit status.
    I think the second part is "ld" not "id" - which is the linker stage failed - because it can't find a function called randn - you may want to try rand() instead.

    You may want to give gcc (the compiler) the switch "-Wall" to give you warnings, that will help you get some more information on things that you do wrong, earlier, rather than at the linker stage, where for example which line the error was on is lost.

    --
    Mats

  5. #20
    Registered User
    Join Date
    Sep 2007
    Posts
    26
    how do i switch wall.

    also i changed to rand and am getting:

    in function 'fight'
    to many arguments to function rand.

  6. #21
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    I updated the fixed code...it works..try it.
    You should read all the replies posted since you last read the topic, not just the last reply.

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't know how you set switches in the Dev environment - somewhere you'll be able to change your settings for how the compiler is called, and you need to say "Give me warnings" there.

    rand() gives you a value within a range 0..RAND_MAX, the latter being a large number. If you use % X where X is one more than the highest number you want, e.g.
    Code:
       r = rand() % 10;   // Numbers 0..9
       r = rand() % 10 + 1 // 1..10
       r = rand() % 300;    // 0..300
    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 08:28 PM
  2. another noob question
    By clb2003 in forum C Programming
    Replies: 4
    Last Post: 02-12-2009, 01:28 PM
  3. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 08:08 PM
  4. Very noob question :(.
    By GamerProduction in forum Tech Board
    Replies: 4
    Last Post: 04-14-2007, 05:40 AM
  5. Noob question ( little dos program )
    By Demon1s in forum C++ Programming
    Replies: 13
    Last Post: 04-04-2003, 09:28 PM