Stuck on the most basic program

Discussion in 'Mac Programming' started by ILoveBASIC, Mar 2, 2010.

  1. ILoveBASIC macrumors newbie

    Joined:
    Mar 2, 2010
    #1
    Hi, found this forum after searchin around the web tryin to figure out what my error messages meant.

    Trying to follow a beginners guide to objective c, using Xcode
    I made a new project under application - command line tool

    Im tryin to make a simple function that i can call, just to do a basic maths calculation.
    Spent hours trying to figure out what im doing wrong, but googlin error messages kinda brings up documentation with all sorts of tech speak :)
    Ive copied my code below - it doesnt copy the error messages so ive typed them manually with **** around them
    Sorry for being so dim, i could program pretty well in BASIC on my Atari ST, but guess things have moved on a bit! Im trying the easiest guide i can find, but i cant even get the second program running :-(
    Any help really appreciated. Is my definition of the function in the wrong place? Again, sorry for being a bit dim.

    #import <Foundation/Foundation.h>

    int main (int argc, const char * argv[]) {


    float circleradius =5;
    float result;
    result = circlearea(circleradius); ****error implicit declaration of function 'circlearea'****
    return 0;
    }

    float circlearea(float wibble)
    { ****error conflicting types for 'circlearea'****
    float thearea;
    thearea = 3.14 * wibble * wibble;
    return thearea;
    }
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Yes. The compiler sees things strictly in the order they are in the file. Either move the function above main or put a function prototype for the function above main and leave the function where it is
     
  3. ILoveBASIC thread starter macrumors newbie

    Joined:
    Mar 2, 2010
    #3
    Oh thanks very much, thats worked :)

    Really appreciate it, thanks
     

Share This Page