Originally Posted by
Pielord
Oh, been looking it up and there seem to be numerous different styles involved, any you would recommend or doesn't it really matter as long as I follow something?
Yup.
The last code looks like the easiest thing to implement, but what exactly these lines:
Code:
structureA triangle;
trig *tri;
structureA.hyp;
structureA.adj;
structureA.opp;
do, I have no idea.
Anyhow, start off with something easy, and then expand upon it. You could start with the above example, basically having the user input whatever information is necessary for the program to calculate the angle.
Then you could go a little more advanced.
Let me show you an example of how you could make a program to let the user enter all three sides (some being unknown) and all three angles (some being unknown) and allow you to calculate angle or sides.
First off, ask user for all sides and angles. User can input 0 if they are unknown.
Then ask what angle to calculate (name the angles 1, 2 and 3).
From that, determine the opposite side, etc. Then calculate.
A simple example might look like:
Code:
std::array<int, 3> side;
std::array<int, 3> angle;
int angle_to_calc;
std::cout << "Enter sides (0 for unknown): ";
std::cin >> side[0] >> side[1] >> side[2];
std::cout << "Enter angles (0 for unknown): ";
std::cin >> angle[0] >> angle[1] >> angle[2];
std::cout << "Enter angle to calculate: ";
std::cin >> angle_to_calc;
int hypol = side[1], oppol, nearl;
switch (angle_to_calc)
{
case 1: oppol = side[3]; nearl = side[2]; break;
case 2: oppol = side[2]; nearl = side[3]; break;
}
float result;
if (hypol != 0 && nearl != 0)
result = acos((float)nearl / hypol);
else if (hypol != 0 && oppol != 0)
result = asin((float)oppol / hypol);
else if (nearl != 0 && hypol != 0)
result = atan((float)oppol / nearl);
else
{
std::cout << "Insufficient information to calculate angle!\n";
return 1;
}
std::cout << "The angle is " << result << " radians.\n";
You could make it more complicated, for example, if some needed information is not known, it could try calculating that unknown information. Say you need the hypotenuse. You might calculate that using some other known information. And if some information needed to calculate that is unknown, you could calculate that unknown with some other known information.
That might be a little tricky, but it's certainly possible (especially using recursion).