Hypotenuse of a triangle

can someone help me i have to create a Hypotenuse of a triangle app, the user has to give the angle an the opposite, im a beginner so i dont no how to start

You do learn best by doing.

Your program clearly has to get the two numbers from the user. You have discussed input, have you not?

Then calculate. Simple math.

Last output the result.
the thing i cant work out is the the maths side of it?
sin(theta) = opposite/Hypotenuse

transpose for Hypotenuse and bob's your goldfish.


be sure to check in the sin function needs the angle in radians or degrees.
thanks for that but im not shore what you are saying or were to put it, heres my code

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// to calculate the area of circle
#include <iostream>
// define identifier PI with a constant
#define PI 3.14159
// define identifier TWO with a constant
#define TWO 2.0

using namespace std;

char menu()
{
    char choice;
    cout<< "\nMaths Helper";
    cout<< "\n\n**************************************\n";
    cout<< "\n\n Please choose one of the following:\n";
    cout<< "\n\n 1 - Area of a circle ";
    cout<< "\n 2 - Circumference of a circle ";
    cout<< "\n 3 - Factorial of a number ";
    cout<< "\n 4 - Hypotenuse of a triangle ";
    cout<< "\n 5 - Exit";
    cout<< "\n\n\n**************************************\n";
    cout<< "\n\n Enter you choice and press return: ";
    cin >> choice;
    return choice;
}

int main()
{
    int num,factorial=1,Angle, Opposite;
    float area, radius, circumference;
    
    char choice;
    
    do
    {
        choice = menu();
        
        switch (choice)
        {
            case '1':
                cout << "\n\nArea of a circle"
                     << "\n\nEnter the radius:";
                cin >> radius;
                // area = PI*radius*radius
                area = PI * radius * radius;
                // circle area
                cout << "\nCircle area = " << area << endl;
                // Pause for user
                system("pause");
            break;             
            case '2':
                cout<< "\n\nCircumference of a circle"
                    <<"\n\nEnter a circumference of a circle:";
                cin>>radius;
                // circumference = 2*PI*radius
                circumference = TWO * PI * radius;
                // circle Circumference
                cout<<"\nCircumference = "<<circumference<<endl;
                // Pause for user
                system("pause");
            break;
            case '3':
                cout<< "\n\nFactorial of a number "
                    <<"\n\nEnter a number to find its factorial:";
                    cin>>num;
                    // a = 1, number less then 1 equals number, increase the number by 1 
                    for(int a=1;a<=num;a++)
                    {
                    // factorial = 1 * 
                    factorial=factorial*a;
                    }
                    //Factorial number
                    cout<<"\n\nFactorial number is ="<<factorial<<endl;
                    // Pause for user
                    system("pause");
                break;
            case '4':
                cout<< "\n\nHypotenuse of a triangle "
                    << "\n\n Enter a Angle:";
                cin>>Angle;
                cout<< "\n\n Enter the Opposite:";
                cin>>Opposite;
                
                system("pause");
                break; 
            case '5':
                cout<< "Exit"; 
                break;
            default:
                cout<< "\nNot a valid choice.";
        }
    } while (choice != '5');

    return 0;
} 
By the way, in c++ it is preferable to use a const rather than #define for values such as PI. That's because the compiler is able to check the type (e,g. double or int etc.) and do better validation of the correctness of the code you write, whereas the #define (at least in this case) is doing a plain text substitution.
Topic archived. No new replies allowed.