Triangle solving program assignment

So here's my code for solving triangles, the first part has no problem, but I can't figure out how to compute the second part, which is to solve by entering the 3 length of the sides. I need to find a way to solve for Cx and Cy. Please help..

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{

cout << "This program is designed to aid in the analysis of triangles.\n";
cout <<"\nWould you like to specify the coordinates of a triangle (C),\n";
cout <<"or the lengths of their sides(S)?\n";
cout <<"\nEnter 'C' or 'S':";
char X ;
cin >> X;
if( X=='C'){

double Ax,Ay,Bx,By,Cx,Cy;
cout <<"\nEnter the x coordinate of point A:";
cin >>Ax;
cout <<"\nEnter the y coordinate of point A:";
cin >>Ay;
cout <<"\nEnter the x coordinate of point B:";
cin >>Bx;
cout <<"\nEnter the y coordinate of point B:";
cin >>By;
cout <<"\nEnter the x coordinate of point C:";
cin >>Cx;
cout <<"\nEnter the y coordinate of point C:";
cin >>Cy;

double a = sqrt(((Bx-Cx)*(Bx-Cx))+((By-Cy)*(By-Cy))); ///distance formula
double b = sqrt(((Cx-Ax)*(Cx-Ax))+((Cy-Ay)*(Cy-Ay)));
double c = sqrt(((Ax-Bx)*(Ax-Bx))+((Ay-By)*(Ay-By)));
double A = acos(((b*b)+(c*c)-(a*a))/2*b*c); ///law of cosine
double B = asin(b*sin(A)/a); ///law of sine
double C = asin(c*sin(A)/a);
cout <<"\nThe lengths are a= " << a << " ,b= " << b << " ,c=" <<c;
cout <<"\nThe angles are A= " << A <<" ,B= " << B << " ,C= " << C;

}

else if(X =='S'){

double a,b,c;
cout <<"\nEnter the length of side a:";
cin >>a;
cout <<"\nEnter the length of side b:";
cin >>b;
cout <<"\nEnter the length of side c:";
cin >>c;

double A = acos(((b*b)+(c*c)-(a*a))/2*b*c);
double B = asin(b*sin(A)/a);
double C = asin(c*sin(A)/a);
double Ax =0;
double Ay =0;
double Bx =c;
double By =0;
double Cx =0;
double Cy =0;

if(a+b>c, b+c>a, a+c>b){
cout <<"\nThe coordinates are A(" <<Ax <<","<<Ay <<") , B("<<Bx <<","<<By<<") , C("<<Cx<<","<<Cy<<") ";
cout <<"\nThe angles are A= " << A <<" ,B= " << B << " ,C= " << C;
}


}






return 0;
}
Last edited on
You know the lengths of all 3, and you can compute the angles, but that isn't enough information to find the coordinates of the triangle. You'd need the coordinates of two points to lock down the coordinate of the third.
With only the lengths of the sides, I'm pretty sure the best you can do is find each angle.
You can save a little computation here, though. You only need to compute the first two angles. Just subtract those from 180 to get the third angle.
Topic archived. No new replies allowed.