Originally Posted by Pielord
The last code looks like the easiest thing to implement, but what exactly these lines:
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:
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.
std::array<int, 3> side;
std::array<int, 3> angle;
std::cout << "Enter sides (0 for unknown): ";
std::cin >> side >> side >> side;
std::cout << "Enter angles (0 for unknown): ";
std::cin >> angle >> angle >> angle;
std::cout << "Enter angle to calculate: ";
std::cin >> angle_to_calc;
int hypol = side, oppol, nearl;
case 1: oppol = side; nearl = side; break;
case 2: oppol = side; nearl = side; break;
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);
std::cout << "Insufficient information to calculate angle!\n";
std::cout << "The angle is " << result << " radians.\n";
That might be a little tricky, but it's certainly possible (especially using recursion).