Hey folks, I recently decided to go back to school in an effort to learn c++, I am currently 4 weeks into my first class and finally got my first homework assignment. The assignment was to write a program that would calculate the hypotenuse of a right triangle after the user input 2 sides. I have already done that, yay, so I set myself an extra challenge to try and also make the program calculate the remaining angles of the triangle. This was just for my own practice because, let's face it, that's how we learn. Anyway, I pretty immediatly ran into two problems:
1)this is way ahead of what we're learning in class
and 2)apparently I was one of those kids who went "pffft, we're never gonna use this!" in math class low those many years ago. So my first challenge was to teach myself how to do the equations. Math was a while ago.
Anyways, I thought the best way to start would be to write an absurdly simple program that started with two known variables for the sides, and attempt to calculate one angle. This is what I came up with:
using namespace std;
double a = 3, b = 4, angle;
angle = atan(a / b);
cout << "The angle is: " << angle << endl;
Now, I know from doing the math myself that if a right triangle has two sides 3 and 4, the hypotenus is 5 and one of the angles is 36.87.
When ran, that program outputs 0.643501. I'm fairly inept at math but I'm pretty sure that's not 36.87.
Now, I could probably find sample code online that would do the trick, but the whole point of this excercise is to try and learn how to do this on my own. If I just jam in some sample code I don't understand, I haven't learned anything, and that's not very good. So, I am pretty sure my code is very wrong, what do I do to make it right?
Thank you in advance, yes I know I kind of suck at this. Thanks!