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
#include <iostream>
#include <cmath>
#include <iomanip>
usingnamespace 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.
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