### 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?

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677`` ``````#include 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.