Help with class problem

Ok my class has 2 functions that add input together and the first one adds ok but the second one is all crazy its like -5565434 why is that?

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
#include <iostream>

using namespace std;

class Triangle
{
    private:
        int sideA, sideB, sideC;
        int sideD, sideE, sideF;

    public:
        void set_Tri_one(int, int, int);
        void set_Tri_Two(int, int, int);
        int Tri_One_Area()
        {
            return(sideA + sideB + sideC);
        }
        int Tri_Two_Area()
        {
            return(sideD + sideE + sideF);
        }
};

void Triangle::set_Tri_one(int TP, int LP, int RP)
{
    sideA = TP;
    sideB = LP;
    sideC = RP;
}

void Triangle::set_Tri_Two(int TP2, int LP2, int RP2)
{
    sideD = TP2;
    sideE = LP2;
    sideF = RP2;
}

int main()
{
    int A = 0;
    int B = 0;
    int C = 0;

    int D = 0;
    int E = 0;
    int F = 0;

    cout << "Enter 3 numbers" << endl;
    cout << "Number 1" << endl;
    cin >> A;
    cout << "Number 2" << endl;
    cin >> B;
    cout << "Number 3" << endl;
    cin >> C;

    Triangle T;
    T.set_Tri_one(A,B,C);
    cout << "Triangle 1 Total Area: " << T.Tri_One_Area() << endl;

    cout << "\n";

    cout << "Number 4" << endl;
    cin >> D;
    cout << "Number 5" << endl;
    cin >> E;
    cout << "Number 6" << endl;
    cin >> F;

    cout << "\n";

    Triangle T2;
    T2.set_Tri_Two(D,E,F);
    cout << "Triangle 2 Total Area: " << T.Tri_Two_Area() << endl;

    cin.get();
    return 0;
}
Line 73: You have used T instead of T2 here.
oh lol, im an idiot thanks :)
I have one more question actually, why in the class is int declared with no name? this part

void set_Tri_one(int, int, int);

there just three ints, they dont have a name for them so what does that do? i always thought a type had to have a name like this

int i = 56;

??
The method prototype doesn't need to know the names of the arguments passed in, just the types of those arguments.

It's only when you actually define the functions that the arguments need actual names.
Ok so its absolutley necessary that i declare the type in the parameters? What is the point of that?
Because that's the whole point of the declaration - so that when the compiler reaches the code that calls the method, it understands that it is a method, and it can check that the parameters are correct.
Last edited on
I would just like to mention you are calculating perimeter not area in those functions.
Topic archived. No new replies allowed.