Please help me with some simple code

Discussion in 'Public Game Developers Forum' started by Evre1, Jul 8, 2012.

  1. Evre1

    Evre1 New Member

    Jul 8, 2012
    I just want to make a simple program that displays a message on my iPhone screen. I've been following the guide at

    and I put some of their example code into the main.m file in my Xcode software, and when I run the simulator all I get is either a blank screen or the app just closes and doesn't run.

    How can I get this code to work?

    #import <Foundation/Foundation.h>
    float circleArea(float theRadius);
    float rectangleArea(float width, float height);
    int main()
    float pictureWidth, pictureHeight, pictureSurfaceArea,
    circleRadius, circleSurfaceArea;
    pictureWidth = 8.0;
    pictureHeight = 4.5;
    circleRadius = 5.0;
    pictureSurfaceArea = rectangleArea(pictureWidth, pictureHeight);
    circleSurfaceArea = circleArea(circleRadius);
    NSLog(@"Area of circle: %10.2f.", circleSurfaceArea);
    NSLog(@"Area of picture: %f. ", pictureSurfaceArea);
    return 0;
    float circleArea(float theRadius) // first custom function
    float theArea;
    theArea = 3.1416 * theRadius * theRadius;
    return theArea;
    float rectangleArea(float width, float height) // second custom function
    return width*height;

    I just want to find some code that produces a result so I can build from that knowledge.

    If I put that into the main.m the app just closes when I run it.
  2. ruiznick

    ruiznick Active Member

    To get a basic understanding of programming, I suggest following along with

    After you build up that knowledge and are interested in making games, then I suggest following some cocos2D tutorials.

    If programming is very new to you and are lost in the woods, then I would suggest skipping objective-c and starting with Unity. You will still build that basic foundation of understanding, but Unity is more visual and there are a lot of resources to get into it quickly. Another plus about Unity is that its multi-platform.

Share This Page