★ TouchArcade needs your help. Click here to support us on Patreon.

Please help me with some simple code

07-08-2012, 11:51 AM
Junior Member [Original Poster]
Joined: Jul 2012
Posts: 1
Please help me with some simple code

I just want to make a simple program that displays a message on my iPhone screen. I've been following the guide at http://www.cocoalab.com/BecomeAnXcoder

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.
07-08-2012, 12:40 PM
Joined: Mar 2012
Location: California
Posts: 31
To get a basic understanding of programming, I suggest following along with http://thenewboston.org/list.php?cat=33

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.

Twitter: RuizNick