Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

myvsiac

macrumors newbie
Original poster
Jan 28, 2010
2
0
Hi. I'm new at programming. I bought an objective -c book and I just followed the book. I don't know why I get three errors. Help!

Code:
#import <Foundation/Foundation.h>

// returns NO if the two intergers have the same
// value, YES otherwise

BOOL areIntsDifferent (int thing1, int thing2)
{
	if (thing1 == thing2) {
		return (NO);
	} else {
		return (YES);
	} // areIntsDifferent

// given a YES value, return the human-readable
// string "YES". Otherwise return "NO"

NSString *boolString (BOOL yesNo)
	{ *Nested functions are disabled, use -fnested-functions to re-enable*
		if (yesNo == NO) {
			return (@"NO");
		} else {
			return (@"YES");
		}

	} // boolString

int main (int argc, const char *argv[])
	{ *Nested functions are disabled, use -fnested-functions to re-enable*
		BOOL areTheyDifferent;

		areTheyDifferent = areIntsDifferent (5, 5);

NSLog (@"are %d and %d different? %@",
	   5, 5, boolString(areTheyDifferent));

		areTheyDifferent = areIntsDifferent (23, 42);

NSLog (@"are %d and %d different? %d",
	   23, 42, boolString(areTheyDifferent));

		return(0);

	} // main *Expected declaration or statement at end of input*

I got two nested functions error and one expected declaration error.

Help me, please!
 
You'll kick yourself - you're missing the closing bracket for the areIntsDifferent function. The compiler thinks you're trying to define the other functions inside areIntsDifferent.
 
You'll kick yourself - you're missing the closing bracket for the areIntsDifferent function. The compiler thinks you're trying to define the other functions inside areIntsDifferent.

Thank you!
I couldn't see it!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.