Ok, This program is designed to output sides and angles of a triangle based upon a side and angle that is inputted by the user. When I run the program the lenghts of the sides that I receive make absolutely no sense..but when I do them in my calculator they work out perfectly..I have bolded the two lines that have been giving me trouble, I'm at witts end trying to figure out why the heck this isn't working!

``````using namespace std;
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
int main()
{
double angle1, side1, angle2, side2, angle3, side3, PI= 4.0*atan(1.0), perimiter, area;
ofstream tofile ("Results.txt");
cout<<"Enter value of angle 1 and side opposite of angle"<<endl;
cin>>angle1>>side1;
if (angle1>(PI/2)*(180/PI))
{
cout<<"error: angle cannot be greater than 90"<<endl;
}
if (angle1<=(PI/2)*(180/PI))
{
[B]side3=(side1)/(sin(angle1));
side2=(side1)/(tan(angle1));[/B]
cout<<"Side 2="<<side2<<endl;
cout<<"Side 3="<<side3<<endl;
angle2=((PI/2)*(180/PI))-(angle1);
angle3=((PI/2)*(180/PI));
cout<<"Angle 2="<<angle2<<endl;
cout<<"Angle 3="<<angle3<<endl;
perimiter=(side1)+(side2)+(side3);
cout<<"Perimiter="<<perimiter<<endl;
area=((side1*side2)/2);
cout<<"Area="<<area<<endl;
}
if (area>100)
{
cout<<"this is a large triangle"<<endl;
}
tofile<<"Side 2="<<side2<<endl;
tofile<<"Side 3="<<side3<<endl;
tofile<<"Angle 2="<<angle2<<endl;
tofile<<"Angle 3="<<angle2<<endl;
tofile<<"Area="<<area<<endl;
tofile<<"Perimiter="<<perimiter<<endl;

system("pause");
return 0;
}``````

Ok, This program is designed to output sides and angles of a triangle based upon a side and angle that is inputted by the user. When I run the program the lenghts of the sides that I receive make absolutely no sense..but when I do them in my calculator they work out perfectly..I have bolded the two lines that have been giving me trouble, I'm at witts end trying to figure out why the heck this isn't working!

``````using namespace std;
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
int main()
{
double angle1, side1, angle2, side2, angle3, side3, PI= 4.0*atan(1.0), perimiter, area;
ofstream tofile ("Results.txt");
cout<<"Enter value of angle 1 and side opposite of angle"<<endl;
cin>>angle1>>side1;
if (angle1>(PI/2)*(180/PI))
{
cout<<"error: angle cannot be greater than 90"<<endl;
}
if (angle1<=(PI/2)*(180/PI))
{
[B]side3=(side1)/(sin(angle1));
side2=(side1)/(tan(angle1));[/B]
cout<<"Side 2="<<side2<<endl;
cout<<"Side 3="<<side3<<endl;
angle2=((PI/2)*(180/PI))-(angle1);
angle3=((PI/2)*(180/PI));
cout<<"Angle 2="<<angle2<<endl;
cout<<"Angle 3="<<angle3<<endl;
perimiter=(side1)+(side2)+(side3);
cout<<"Perimiter="<<perimiter<<endl;
area=((side1*side2)/2);
cout<<"Area="<<area<<endl;
}
if (area>100)
{
cout<<"this is a large triangle"<<endl;
}
tofile<<"Side 2="<<side2<<endl;
tofile<<"Side 3="<<side3<<endl;
tofile<<"Angle 2="<<angle2<<endl;
tofile<<"Angle 3="<<angle2<<endl;
tofile<<"Area="<<area<<endl;
tofile<<"Perimiter="<<perimiter<<endl;

system("pause");
return 0;
}``````

I only see you asking for one angle and its opposite side as input. I can make more than triangle from that, so I am either missing an assumption you are making, not understanding what you are trying to do, or your formula is flawed.

What if the user inputs the longest side (side1)?

``side3=(side1)/(sin(angle1));``

side3 has to be at least as long as side1 from this formula, so if there are restrictions/assumptions, you should state them. Again, without some more restrictions, you can't construct a unique triangle from an angle and its opposite side. For example, I can create an infinite number of triangles from an angle of 30 degrees and an opposite side of length 1.

The assignment is to write a program that outputs the other two sides and angles based upon what you put in...i understand what youre saying but have no clue how to work towards a solution

The trigonometric functions expect their arguments to be in radians. Your input expects values in degrees. `(PI/2)*(180/PI)` is kind of funny; it simplifies to 90...

The assignment is to write a program that outputs the other two sides and angles based upon what you put in...i understand what youre saying but have no clue how to work towards a solution

The assignment either has assumptions that you are allowed to make, is impossible, or you are allowed to ask for more than just an angle and an opposite side. If the goal is to create a unique triangle from an angle and an opposite side, this is mathematically impossible. If you are simply to construct ONE OF THE MANY POSSIBLE triangles, that can be done. My guess is that you are supposed to assume that it is an isosceles triangle or a right triangle or you are supposed to ask for at least one more side or angle. But what you said about getting the correct answer when you put it into a calculator doesn't make sense to me since more than one triangle can be created.

The assignment either has assumptions that you are allowed to make, is impossible, or you are allowed to ask for more than just an angle and an opposite side. If the goal is to create a unique triangle from an angle and an opposite side, this is mathematically impossible. If you are simply to construct ONE OF THE MANY POSSIBLE triangles, that can be done. My guess is that you are supposed to assume that it is an isosceles triangle or a right triangle or you are supposed to ask for at least one more side or angle. But what you said about getting the correct answer when you put it into a calculator doesn't make sense to me since more than one triangle can be created.

1. Write a C++ program that does the following.

a. Reads from the key board two numbers using 2 double precision variables named: angle1 and side1 . The variable angle1 is one of the angles of a right triangle and side1 is the length of the side that is opposite angle1.

yes, it is supposed to be a right triangle, and all they want is if they put in a number it gives them possible angles, so yes they want any possible triangle that can be made.

1. Write a C++ program that does the following.

a. Reads from the key board two numbers using 2 double precision variables named: angle1 and side1 . The variable angle1 is one of the angles of a right triangle and side1 is the length of the side that is opposite angle1.

yes, it is supposed to be a right triangle, and all they want is if they put in a number it gives them possible angles, so yes they want any possible triangle that can be made.

Well, that's doable.

Rashakil Fol is correct and I imagine that is what your problem is. Explicitly tell the user whether you want the input in radians or degrees so they know. Keep it consistent when you store them. As Rashakil Fol mentioned, however you store them, when you take the sine and tangent, you need to pass them arguments which are in radians. You are bound to have errors if you mix up radians and degrees.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.