Getting Trash Output- no undefined variable

There is no variable where I am getting the output.

it is the 5007465 number.

it happens no matter which if or else if or else path I go down

--Triangle Calculator--

Please enter side A: 1
Please enter side B: -10
Value entered must be positive!
Please enter side B: 1
Please enter side C: 1
This is an EQUILATERAL triangle, all sides are equal
5007456------ on this line--------------
Would you like to repeat? (1-Yes, 2-No): 2



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
#include <iostream>
using namespace std;

int triangleType(int a, int b, int c);

int main()
{
    int A, B, C, go;
cout << "--Triangle Calculator--\n\n";
    while (true)
    {
        cout << "Please enter side A: ";
        cin >> A;
        while (A <= 0)
        {
            cout << "Value entered must be positive!\n"
                 << "Please enter side A: ";
            cin >> A;
        }

        cout << "Please enter side B: ";
        cin >> B;
        while (B <= 0)
        {
            cout << "Value entered must be positive!\n"
                 << "Please enter side B: ";
            cin >> B;
        }

        cout << "Please enter side C: ";
        cin >> C;
        while (C <= 0)
        {
            cout << "Value entered must be positive!\n"
                 << "Please enter side C: ";
            cin >> C;
        }
        A = A ^ 2;
        B = B ^ 2;
        C = C ^ 2;
        cout << triangleType(A, B, C) << endl;

        cout << "Would you like to repeat? (1-Yes, 2-No): ";
        cin >> go;
        if (go != 1)
            break;
    }

    return 0;
}

int triangleType(int a, int b, int c)
{
    if ( (a == b) && (b == c) && (c == a) )
    {
        cout << "This is an EQUILATERAL triangle, all sides"
             << " are equal\n";
    }
    else if ( (a == (b + c) ) || (b == (a + b) )
            || (c == (b + a) ) )
    {
        cout << "This is a RIGHT triangle, where there is"
             << " a 90 degree angle\n";
    }
    else if ( ( (a == b) && (b != c) ) || ( (b == c) && (c != a))
            || ( (c == a) && (a != b) ) )
        cout << "This is an ISOSCELES triangle, where only"
             << " two side are equal\n";
    else
    {
        cout << "This is a OTHER kind of triangle, NOT ISOSCELES,"
             << " NOT RIGHT, and NOT EQUILATERAL.\n";
    }
}
Last edited on
triangleType() returns an int, which you are sending to std::cout on line 41:
cout << triangleType(A, B, C)
But you never return anything from triangleType(), so the return value is undefined.

You probably wanted triangleType() to be void. Then you should not print anything on line 41.
Topic archived. No new replies allowed.