## Chapter 5 Challenge in Objective C Programming

General comments and announcements about "iPhone Programming: The Big Nerd Ranch Guide"

### Chapter 5 Challenge in Objective C Programming

Whats up guys, I am new to programming and am trying to create this function for the challenge in chapter 5 Objective C programming, but am having issues on how to write this function. If the triangle is to add up to 180 degrees, The out put should read "The Third angles is 90". Can anyone offer some insight as to how I am suppose to write out this function to display this output in the console? Or at least give me a hint? Thanks

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

float angleA = 30;
float angleB = 60;
float AngleC = remainingAngle(angleA, angleB);
printf("The third angle is %.2f\n", angleC);
return 0;
}
christos0603

Posts: 3
Joined: Sat Jan 07, 2012 3:43 pm

### Re: Chapter 5 Challenge in Objective C Programming

The function would be -

(float) remainingAngle( float A, float B)
{
float C = A + B;
return C;
}

S.
Last edited by resplendent2209 on Sun Jan 15, 2012 5:55 pm, edited 1 time in total.
resplendent2209

Posts: 9
Joined: Mon Dec 26, 2011 1:34 am

### Re: Chapter 5 Challenge in Objective C Programming

Makes sense. Thanks a lot!!
christos0603

Posts: 3
Joined: Sat Jan 07, 2012 3:43 pm

### Re: Chapter 5 Challenge in Objective C Programming

Shouldn't the answer to this question technically be?

float remainingAngle (float A, float B)
{
float C = 180 - (A + B);
return C;
}
kobashidriver

Posts: 1
Joined: Wed Feb 15, 2012 9:39 am

### Re: Chapter 5 Challenge in Objective C Programming

kobashidriver is correct in his reply. Here is an even more robust version with error checking.

/*******************************************************************/
float
remainingAngle( float angleA, float angleB ){

/* The sum of a triangles three angles must equal 180 degrees */
float sum = angleA + angleB;
if( sum < 2.0 || sum >= 180.0 ){
// Error
return( 0.0 );
}
return( 180.0 - sum );

} // remainingAngle()

/*******************************************************************/
calwas

Posts: 21
Joined: Tue Jul 24, 2012 9:34 pm

### Re: Chapter 5 Challenge in Objective C Programming

Oh my goodness.
Thank you for this.

For some reason, I just wasn't seeing this. I was getting close, but eek. This was great; helped me understand a lot more again. I was re-reading chapters over and over trying to figure out what I was missing, when it was so simple. ._.
Katreya

Posts: 2
Joined: Mon Jul 30, 2012 4:59 am

### Who is online

Users browsing this forum: No registered users and 1 guest