Here is my answer to the challenge at the end of Chapter 5. I worked it for about an hour and finally came up with a solution that spits out the correct answer, however, I have little idea about how this program is delivering the answer. So…I think the best way to go about my question is to tell you what I think is going on and then hopefully someone can set me straight.
- There are two frames in this program.
- When I compile and run this program it starts with the “main” function first and then proceeds to wherever “main” has told it to go. (this is a little confusing because the graphics in the book always show main on the bottom of the stacks. If its first why is it on the bottom?)
- I have declared my variables and known values to be floating, this means that they can contain 8 digits on either side of the decimal.
- After the floatAngleC = is read the program jumps up to my second frame and labeled “float remainingAngle(float angleA, float angleB)”
- The function of the second frame is "float angleC = 180 - angleA - angleB;
- angleC is returned to the printf command at the end of “main”
- program ends
float remainingAngle(float angleA, float angleB)
float angleC = 180 - angleA - angleB;
int main(int argc, const char * argv)
float angleA = 20.0;
float angleB = 60.0;
float angleC = remainingAngle(angleA,angleB);
printf(“The third angle is %.2f\n”, angleC);