Trig Calculator Help

Hello.
I am new to programming and i would like some help.
For my program i need to use functions to calculate the hypotenuse and four trigonometric values (sine, cosine, tangent, and cotangent) for a right triangle of arbitrary size. I need to provide the answer in degrees rather than radians.

I need help with writing my functions
Allow the program to continue doing calculations for various triangles until the user wants to stop. Which means that your main function will have a sentinel or flag controlled while loop or do-while loop.I have provide what i have started with
Image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double adjacent_len;
double opposite_len;
double hypotenuse;


//const double PI = 3.14159265359;
//const double Deg = (180 / PI);
double calcSine()
{
sin = sin( opposite_len / hypotenuse)
}
double calcCos()
{
cos = cos( adjacent_len / hypotenuse)
}
double calcTan()
{
tan = tan(opposite_len / adjacent_len)
}
double calcCoTan()
{
coTan = (adjacent_len / hypotenuse)
}

double hypotenuse()
{
hypotenuse = sqrt(pow(opposite, 2) + pow(adjacent, 2));
}

int main()
{
cout << "Welcome to the trigonometry calculator." << endl;
cout << "Please tell me the lengths of the adjacent and opposite " << endl;
cout << "sides of a right triangle" << endl;
cout << "What is the adjacent side length : ";
cin >> adjacent_len;
cout << "What is the opposite side length : ";
cin >> opposite_len;

cout << "Based on an adjacent side of " << adjacent_len
<< "and an opposite side of" << opposite_len << ",";
double calcHypo (double adjacent, double opposite);
cout << " The hypotenuse has length : " << hypotenuse << endl;
double calcSine(double opposite_len, double hypotenuse);
cout << "The sine of the angle is : " << calcSine() << endl;
// to get the answer in degrees i wouls multiple by my const double deg
double calcCos(double adjacent_len, double hypotenuse);
cout << "The cosine of the angle is : " << calcCos() << endl;
double calcTan(double opposite_len, double adjacent_len);
cout << "The tangent of the angle is :" << calcCoTan()<< endl;
double calcCoTan(double opposite_len, double adjacent_len);
cout << "The cotangent of the angle is :" << calcCoTan() << endl;
//cout << "Using an approximation of arctangent, the angle in degrees is :";
}
// my main function will have a sentinel or flag controlled 
//while loop or do-while loop. Inside of the loop (within the curly braces) 
//and will call all of the functions listed above. 
Last edited on
closed account (48T7M4Gy)
1. We don't do homework.
2. Posting this twice doesn't increase your chances of overcoming 1 above.
Thank you.
But its not homework and i just opened this account today so i am
still exploring how thing work.
Thanks for the help and comment tho.
-kemort
Last edited on
closed account (48T7M4Gy)
OK - you're forgiven.

What you need to do is start SIMPLE and just have a few lines of code - say for just one function instead of a great pile.

Take calcSine() for instance.


closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

//const double PI = 3.14159265359;
//const double Deg = (180 / PI);

double calcSine( double, double );

int main()
{
    double opp, hyp;
    
    cin >> opp;
    cin >> hyp;
    
    cout << "The sine of the angle is : " << calcSine(opp, hyp) << endl;
    return 0;
}

double calcSine(double opposite_len, double hypotenuse)
{
   return opposite_len/hypotenuse;
}
I have updated my code to this
1
2
3
4
5

#include <iostream>

got it  thanks everyone!
Last edited on
your decleration and implementation are different...

you have 2 doubles at the implementation and 1 at the decleration
1
2
3
4
5
// decleration
double calcArcTan(double calcTan);

// implementation
double calcArcTan(double opposite_len, double adjacent_len )
Topic archived. No new replies allowed.