#include <cstdlib>
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
int angle, hyp, adj, opp;
double sct, final;
cout << "Welcome to trig_calc_beta" << endl;
cout << "COMMANDS:\n-00000: NOT USED\n-00001: variable x" << endl;
cout << "Included angle: ";
cin >> angle;
cout << "Hypotenuse: ";
cin >> hyp;
cout << "Adjacent: ";
cin >> adj;
cout << "Opposite: ";
cin >> opp;
if (opp == 00001 && adj == 00000)
{
sct = sin(angle);
cout << "The sine of " << angle << " is " << sct << endl;
final = sct * hyp;
cout << sct << " * " << hyp << " = " << final << endl;
cout << "X = " << final << endl;
cin.ignore();
}
if (adj == 00001 && opp == 00000)
{
sct = cos(angle);
cout << "The cosine of " << angle << " is " << sct << endl;
final = sct * hyp;
cout << sct << " * " << hyp << " = " << final << endl;
cout << "X = " << final << endl;
cin.ignore();
}
if (opp == 00001 && hyp == 00000)
{
sct = tan(angle);
cout << "The tangent of " << angle << " is " << sct << endl;
final = sct * adj;
cout << sct << " * " << adj << " = " << final << endl;
cout << "X = " << final << endl;
cin.ignore();
}
system("PAUSE");
}
It's completely butchering the answers. For example enter:
included angle: 37
hypotenuse: 00000
adjacent: 100
opposite: 00001
It completely does tan wrong in that problem. Why is that? Am I using tangent wrong?
I guess I should probably clarify how it's working. First off it starts out collecting data. Self-explanatory all but the fact instead of entering a letter for the variable you enter 00001. Also for the side that's not used you enter 00000. Those are my default numbers. Then decides if it's working with sine, cosine, or tangent. Then it calculates the answer and outputs the work and the answer. Make sense?
You are calculating 3 cases where in each one you have a side being 0 and a side being 1. Is this what you want? I mean I think you are not taking into consideration a general case where none is 0.
Basically it would really help to explain what do you expect your code to do.
The 00000 and 00001 are just to tell the computer that it's working with 00000 being the number that's not being used and 00001 then number that's a variable.
It's supposed to get the parameters of a right triangle, decide if its cosine, sine, or tangent (the if statements) then output the work it takes to find the missing side length.
The 0s and 1s are not used at all except for identifying if it's sin, cos, or tan. They would not be effecting my problem. My problem is when I run the code it either
A) shuts down prematurely
B) Does not display an answer at all
C) Displays the incorrect answer
Any any aspect of of 0.0 iis a degenerate triangle and you can end there.
cos, sin and tangent use radians, not degrees.
radians = degree * M_PI/180;
Start there and come back if you have problems.
I'm surprised you're getting correct results from sin and cos.
Indent your code to separate the blocks of execution from each other.
Also, you're asking for absolutes on every aspect of a triangle. An angle of 30 with a hypotenuse of 1 may not meet the requirements of a triangle that has an opposite of 30 and an adjacent of 10.