Chapter 5 Challenge in Objective C Programming


#1

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

//add your new function

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;
}


#2

The function would be -

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

S.


#3

Makes sense. Thanks a lot!!


#4

Shouldn’t the answer to this question technically be?

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


#5

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()

/*******************************************************************/


#6

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. ._.