# Homework Help: Fortran: Find a triangle's side, plus angles

Tags:
1. Dec 15, 2016

### Techno_Knight

The statement:

In every ABC triangle, the laws of sine (a/sinA = b/sinB = c/sinC) & cosine (c2 = a2 + b2 -2*a*b*cosC) are valid, where a, b & c are the sides opposite to A, B & C respectively.

Write a program that calculates and prints on the computer's screen, the length of c, and also the unit of the angles A & B of an ABC triangle. The lengths of a & b, plus the unit of C (in radians) shall be given by the keyboard.

The attempt at a solution

Here's what I have so far:

PROGRAM

REAL :: pi = 3.14159265

PRINT*, 'ENTER THE FIRST SIDE OF THE TRIANGLE'
PRINT*, 'FIRST SIDE (a) = ', a

PRINT*, 'ENTER THE SECOND SIDE OF THE TRIANGLE'
PRINT*, 'SECOND SIDE (b) = ', b

PRINT*, 'ENTER THE ANGLE BETWEEN THE TWO SIDES'
PRINT*, 'ANGLE IN DEGREE C = ', angle_in_degree_C

c = SQRT (a**2 + b**2 - 2.*a*b*COS(angle_in_radian_C))
PRINT*, 'THIRD SIDE OF TRIANGLE =', c

PRINT*, 'ANGLE IN DEGREE A = ',angle_in_degree_A

END

We were given this assignment on Wednesday for our programming class, and it's due tomorrow. Problem is, the system here is a bit, well, weird, and I know little to nothing about Fortran. I was studying C++ (yes, two languages in one semester that starts in Novemeber and ends in January, amongst the other 6 subjects with a 600pg+ syllabus-and everything is mandatory), so I could realy use the help.

I managed to take a look at the book and with the internet's help, I came up with a way to find the third side of the triangle. My problem now is that I can't find the angles. I checked and saw that the arcsin command is ASIN, but when I put it in my editor, the words become red, and while it compiles, I don't get the desired result.

I could really use some help here. But I warn you, I don't know anything beyond the basic commands, so simplify it as much as you can. I wasn't even planning on taking the subject, but here, things work differently. You get into a department of the University, and you attend mandatory classes that have been assigned to you by the department itself, you can't choose. So, as someone who never "played around" with programming before, it's a bit of hurdle for me to learn Fortran & C++ in ~4 months, amongst the other 6 subjects that go with the Physics Department acceptance.

Any kind of help is appreciated.

2. Dec 15, 2016

### Staff: Mentor

Your program so far is pretty straightforward: prompt for input values for sides a and b and angle C. It then calculates side c, using the Law of Cosines. So far, so good.

At the end, you have a problem, because angle_in_radian_A is undefined, but you use it to assign a value to angle_in_degree_A. You need to switch those two lines. Also, your variable names are more verbose than necessary (IMO). I would use C_deg and C_rad, for the measure of angle C in degrees and radians, respectively. In the very last line you're using the Law of Sines to calculate angle A.

3. Dec 15, 2016

### Techno_Knight

D'oh, of course! Thanks a ton, I tried it and it worked great! But yeah, it'd also be a nice idea to streamline it a bit as well.

Thanks for the help!

4. Dec 15, 2016

### Staff: Mentor

Also, I sympathize your plight in having to take two programming languages at the same time! That has to be tough, especially with no prior background in programming.

5. Dec 15, 2016

### Techno_Knight

Yeah, it sure is. I mean, there's only one month left and the only thing I've managed to do is go through half the syllabus of Physics, with contains 14 Chapters. Calculus, Chemistry and Analytical Geometry/Linear Algebra I haven't even touched! How's someone supposed to get through all these in ~4 months, with the books arriving in Novemeber (the semester officially starts in october and the finals start in January)? Especially when each one has a 600pg syllabus (plus programming). I was interested in programming, but I was gonna start it by my own. Hell, essentially that's what I'm doing anyway, it's not like they're competent here. If it wasn't for this place, it'd have been a lost cause.