Quote:
Originally Posted by o0Zero0o1
The coffe is heating up ... let's see what am i going to do :(
Code:
#include<iostream.h>
#include<math.h>
struct _Coordinate
{
float x;
float y;
};
struct Triangle
{
_Coordinate A;
_Coordinate B;
_Coordinate C;
};
int main()
{
int K,i;
float S,P,p,Side_A,Side_B,Side_C;
cout<<"Number of Triangles = " ;
cin>>K;
for (i=0;i<K;i++)
{
cout<<"Coordinates regarding A="<<endl << "X = ";
cin>>Triangle.A.x;
cout<<"Coordinates regarding A="<<endl << "Y = ";
cin>>Triangle.A.y;
cout<<"Coordinates regarding B="<<endl << "X = ";
cin>>Triangle.B.x;
cout<<"Coordinates regarding B="<<endl << "Y = ";
cin>>Triangle.B.y;
cout<<"Coordinates regarding B="<<endl << "X = ";
cin>>Triangle.C.x;
cout<<"Coordinates regarding C="<<endl << "Y = ";
cin>>Triangle.C.y;
Side_A = sqrt( (Triangle.C.x*Triangle.C.x)-(2*Triangle.B.x*Triangle.C.x)+(Triangle.B.x*Triangle.B.x)+(Triangle.C.y*Triangle.C.y)-(2*Triangle.B.y*Triangle.C.y)+(Triangle.B.y*Triangle.B.y));
Side_B = sqrt( (Triangle.A.x*Triangle.A.x)-(2*Triangle.C.x*Triangle.A.x)+(Triangle.C.x*Triangle.C.x)+(Triangle.A.y*Triangle.A.y)-(2*Triangle.C.y*Triangle.A.y)+(Triangle.C.y*Triangle.C.y));
Side_C = sqrt( (Triangle.B.x*Triangle.B.x)-(2*Triangle.B.x*Triangle.A.x)+(Triangle.A.x*Triangle.A.x)+(Triangle.B.y*Triangle.B.y)-(2*Triangle.A.y*Triangle.B.y)+(Triangle.A.y*Triangle.A.y));
P = Side_A+Side_B+Side_C; //perimeter
p = P/2; //semiperimeter needed for the Heron's formula
S = sqrt(p(p-Side_A)(p-Side_B)(p-Side_C) ); //Heron's formula for finding the area
cout<<"\n The perimeter is = " <<P;
cout<<"\n The are is = " <<S;
cout<<endl;
}
return 0;
}
Cool ... it's like 19errors in the Visual C++ ... can't even understand the errors : |.The loop will work it is just that i have no idea how for example to put the outgoing data regarding each triangle , like :
Number of triangles: 7
..... data inpuiting ....
...calculations .....
output:
Triangle
1 ....
2....
3...
|
Ok i should repeat it a little bit different:
"you HAVE TO declare and initalize the stuff"
Just use the struct like int or float.
Code:
Triangle nomatterwhatnamethishas =
{
0.0, 0.0, //Ax, Ay
0.0, 0.0, //Bx, By
0.0, 0.0 //Cx, Cy
};
Then you access like that:
Code:
nomatterwhatnamethishas.A.x
Or save a value:
Code:
nomatterwhatnamethishas.A.x = 10
Or use cin:
Code:
std::cin >> nomatterwhatnamethishas.A.x
But this all will only work if you declared "nomatterwhatnamethishas" before.
Without declaration and using Triangle.A.x, it will never work!