Novice c++ guy here, trying to wrap my head around arrays and functions. This is supposed to be a program that takes the center and radii from 2 3d spheres and determines if they collide.
#include
#include
#include
using namespace std;
struct sphere
{
float center[3];
float radius;
};
bool sphereDist (sphere &s1, sphere &s2)
{
return (pow(s2.center[0] - s1.center[0], 2) +
pow(s2.center[1] - s1.center[1], 2) +
pow(s2.center[2] - s1.center[2], 2)) <
(s1.radius + s2.radius);
}
void main ()
{
cout <<"Sphere collision detection program, by D.R."<< endl;
cout <<"Input the centers of sphere one"<< endl;
cin>>s1.center;
cout <<"input the radius of sphere one"<< endl;
cin>>s1.radius;
cout <<"Now input the centers of sphere two"<< endl;
cin>>s2.center;
cout <<"Please input the radius of sphere two"<< endl;
cin>>s2.radius;
if (sphereDist == true)
{
cout <<"The spheres collide." << endl;
}
else
{
cout << "the spheres do not collide." <
}
2007-11-29
17:03:23
·
2 answers
·
asked by
dustin_r_85
1
in
Computers & Internet
➔ Programming & Design
** reposted in appropiate subject**
Naturally, the program doesn't work.
1>c:\documents and settings\dustin\my documents\visual studio 2005\projects\tut2\tut2\tut2.cpp(31) : error C2065: 's1' : undeclared identifier
1>c:\documents and settings\dustin\my documents\visual studio 2005\projects\tut2\tut2\tut2.cpp(31) : error C2228: left of '.center' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\dustin\my documents\visual studio 2005\projects\tut2\tut2\tut2.cpp(33) : error C2228: left of '.radius' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\dustin\my documents\visual studio 2005\projects\tut2\tut2\tut2.cpp(35) : error C2065: 's2' : undeclared identifier
1>c:\documents and settings\dustin\my documents\visual studio 2005\projects\tut2\tut2\tut2.cpp(35) : error C2228: left of '.center' must have class/struct/union
.... and on and on, 9 errors, to big to fit here.
2007-11-29
17:06:29 ·
update #1