What's new

Triangle Geometry Calculator

Iconoclast

New member
When I say the measure of angle A is 75, it says 90 - 75 is 154 instead of 15. It also says 180 - 75 is 1,054....

WTF is it with these arithmetic issues? Code below.

Obviously, the program is incomplete. Only right triangles are support right now, once these issues with the program are fixed.
Code:
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int b; //Integer boolean value, 1 meaning Yes and 0 meaning No.
    double m, n; //Measurement storage variables.
    cout<<"Given:  Triangle ABC, A <= B >= C\n\nLet's play 20 Questions!\n";
    cout<<"1.  Do you know the triangle is right?  ";
    cin>>b;
    if (b == 1)
    {
        cout<<"A.  The measure of angle B is 90 degrees.\n";
        cout<<"B.  A < 90 > C\n\n";
        cout<<"2.  Do you know the right triangle is isosceles?  ";
        cin>>b;
        if (b == 1)
        {
            cout<<"C.  AB = BC, AC = sqrt(2) * AB = sqrt(2) * BC\n";
            cout<<"D.  The measures of the other two angles are both 45 degrees.\n\n";
            cout<<"3.  Do you know the length of segment AB or segment BC?  ";
            cin>>b;
            if (b == 1)
            {
                cout<<"4.  What is the length of either segment?  ";
                cin>>m;
                if (m == 1) {cout<<"E.  AC = sqrt(2) = "<<sqrt(2)<<"\n\n";}
                else {cout<<"E.  AC = "<<m<<" * sqrt(2) = "<<m * sqrt(2)<<"\n\n";}
            }
            else
            {
                cout<<"4.  Do you know the length of segment AC?  ";
                cin>>b;
                if (b == 1)
                {
                    cout<<"5.  What is the length of segment AC?  ";
                    cin>>m;
                    cout<<"E.  AB = BC = "<<m<<" / sqrt(2) = "<<m / sqrt(2)<<"\n\n";
                }
                else
                {
                    cout<<"You win this one.\n\n";
                    system("PAUSE");
                    return 0;
                }
            }
        }
        else
        {
            cout<<"3.  Do you know the measure of angle A?  ";
            cin>>b;
            if (b == 1)
            {
                cout<<"4.  Enter the measure of angle A in degrees.  ";
                cin>>m;
                cout<<"C.  C = 90 - "<<m<<" = "<<90 - m;
                if (m == 30)
                {
                    cout<<"D.  The measure of angle C is 60 degrees.";
                    cout<<"E.  AB = sqrt(3) * BC, BC = 0.5 * AC, AC = 2 * BC";
                    cout<<"4.  Do you know the length of segment AB?  ";
                    cin>>b;
                    if (b == 1)
                    {
                        cout<<"5.  What is the length of segment AB?  ";
                        cin>>m;
                        cout<<"F.  BC = "<<m<<" / sqrt(3) = "<<m / sqrt(3);
                        cout<<"G.  AC = 2 / sqrt(3) * "<<m<<" = "<<2 / sqrt(3) * m;
                    }
                    else
                    {
                        cout<<"5.  Do you know the length of segment BC?  ";
                        cin>>b;
                        if (b == 1)
                        {
                            cout<<"6.  What is the length of segment BC?  ";
                            cin>>m;
                            cout<<"F.  AB = sqrt(3) * "<<m<<" = "<<sqrt(3) * m;
                            cout<<"G.  AC = 2 * "<<m<<" = "<<2 * m;
                        }
                        else
                        {
                            cout<<"6.  Do you know the length of segment AC?  ";
                            cin>>b;
                            if (b == 1)
                            {
                                cout<<"7.  What is the length of segment AC?  ";
                                cin>>m;
                                cout<<"F.  AB = sqrt(3) / 2 * "<<m<<" = "<<sqrt(3) / 2 * m;
                                cout<<"G.  BC = 0.5 * "<<m<<" = "<<0.5 * m;
                            }
                            else
                            {
                                cout<<"You win this one.\n\n";
                                system("PAUSE");
                                return 0;
                            }
                        }
                    }
                }
                else if (m == 60)
                {
                    cout<<"D.  The measure of angle C is 30 degrees.";
                    cout<<"E.  AB = 0.5 * AC, BC = sqrt(3) * AB, AC = 2 * AB";
                    cout<<"4.  Do you know the length of segment AB?  ";
                    cin>>b;
                    if (b == 1)
                    {
                        cout<<"5.  What is the length of segment AB?  ";
                        cin>>m;
                        cout<<"F.  BC = sqrt(3) * "<<m<<" = "<<sqrt(3) * m;
                        cout<<"G.  AC = 2 * "<<m<<" = "<<2 * m;
                    }
                    else
                    {
                        cout<<"5.  Do you know the length of segment BC?  ";
                        cin>>b;
                        if (b == 1)
                        {
                            cout<<"6.  What is the length of segment BC?  ";
                            cin>>m;
                            cout<<"F.  AB = "<<m<<" / sqrt(3) = "<<m / sqrt(3);
                            cout<<"G.  AC = sqrt(3) / 2 * "<<m<<" = "<<sqrt(3) / 2 * m;
                        }
                        else
                        {
                            cout<<"6.  Do you know the length of segment AC?  ";
                            cin>>b;
                            if (b == 1)
                            {
                                cout<<"7.  What is the length of segment AC?  ";
                                cin>>m;
                                cout<<"F.  AB = 0.5 * "<<m<<" = "<<0.5 * m;
                                cout<<"G.  BC = sqrt(3) / 2 * "<<m<<" = "<<sqrt(3) / 2 * m;
                            }
                            else
                            {
                                cout<<"You win this one.\n\n";
                                system("PAUSE");
                                return 0;
                            }
                        }
                    }
                }
                else if (m == 45)
                {
                    cout<<"D.  AB = BC, AC = sqrt(2) * AB = sqrt(2) * BC\n";
                    cout<<"3.  Do you know the length of segment AB or segment BC?  ";
                    cin>>b;
                    if (b == 1)
                    {
                        cout<<"4.  What is the length of either segment?  ";
                        cin>>m;
                        if (m == 1) {cout<<"E.  AC = sqrt(2) = "<<sqrt(2)<<"\n\n";}
                        else {cout<<"E.  AC = "<<m<<" * sqrt(2) = "<<m * sqrt(2)<<"\n\n";}
                    }
                    else
                    {
                        cout<<"4.  Do you know the length of segment AC?  ";
                        cin>>b;
                        if (b == 1)
                        {
                            cout<<"5.  What is the length of segment AC?  ";
                            cin>>m;
                            if (m == sqrt(2)) {cout<<"E.  AB = BC = 1";}
                            else {cout<<"E.  AB = BC = "<<m<<" / sqrt(2) = "<<m / sqrt(2)<<"\n\n";}
                        }
                        else
                        {
                            cout<<"You win this one.\n\n";
                            system("PAUSE");
                            return 0;
                        }
                    }
                }
                else
                {
                    cout<<"4.  Do you know the length of segment AB?  ";
                    cin>>b;
                    if (b == 1)
                    {
                        cout<<"5.  What is the length of segment AB?  ";
                        cin>>n;
                        cout<<"D.  BC = "<<n<<" * tan("<<m<<") = "<<n * tan(m);
                        cout<<"E.  AC = "<<n<<" / cos("<<m<<") = "<<n / cos(m);
                        
                    }
                    else
                    {
                        cout<<"5.  Do you know the length of segment BC?  ";
                        cin>>b;
                        if (b == 1)
                        {
                            cout<<"6.  What is the length of segment BC?  ";
                            cin>>n;
                            cout<<"D.  AB = "<<n<<" / tan("<<m<<") = "<<n / tan(m);
                            cout<<"E.  AC = "<<n<<" / sin("<<m<<") = "<<n / sin(m);
                        }
                        else
                        {
                            cout<<"6.  Do you know the length of segment AC?  ";
                            cin>>b;
                            if (b == 1)
                            {
                                cout<<"7.  What is the length of segment AC?  ";
                                cin>>n;
                                cout<<"D.  AB = "<<n<<" * cos("<<m<<") = "<<n * cos(m);
                                cout<<"E.  BC = "<<n<<" * sin("<<m<<") = "<<n * sin(m);
                            }
                            else
                            {
                                cout<<"You win this one.\n\n";
                                system("PAUSE");
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<"I win!\n\n";
    system("PAUSE");
    return 0;
}
 
Last edited:

Top