-
December 21st, 2009, 07:23 AM
#1
Problems with functions
well here i have a program with 2 functions 1st one is to send 2 coordinates of the objects and calculate the distance between then, 2nd one is to tell how close they are apart and display a message
i think i have messed up with the types of the functions i used but since i am new at it, i am having hard time understanding where is the problem, could anyone tell me how and why is it there
Code:
#include<iostream>
#include <math.h>
double EUC(double, double);
std::string message(double);
int main()
{
int x1,y1 = 0; //coordinates of 1st object
int x2,y2 = 0; //coordinates of 2nd object
double rx,ry = 0; //final values of coordinates will be stored in these 2 integers
double distance = 0; // answers will be stored is this integer
std::string collision;
std::cout<< "Please enter your 1st object coordinates""\n";
std::cout<< "X: ";
std::cin>> x1;
std::cout<< "Y: ";
std::cin>> y1;
std::cout<< "Please enter your 2nd object coordinates""\n";
std::cout<< "X: ";
std::cin>> x2;
std::cout<< "Y: ";
std::cin>> y2;
rx = x2 - x1; //takes away 1st object coordinates from the 1st one
ry = y2 - y1; //takes away 1st object coordinates from the 1st one
distance = EUC(rx, ry);
std::cout<< "Distance between 1st and 2nd object is: " << distance << "\n"; //displays the output and the value of distance
collision = message(distance);
std::cout<< collision;
}
double EUC(double x, double y)
{
double answer;
//Pythagorean theorem a^2+b^2=c^2/ which is rx^2+ry^2=distance^2
answer = x * x + y * y;
answer = sqrt(answer);
return(answer);
}
std::string message(double close)
{
std::string rtn_msg;
if((close>=0)||(close>=3))
{
rtn_msg = "A collision has accoured";
}
else if ((close>=4)||(close>=6))
{
rtn_msg = "Near miss has accoured";
}
else
{
rtn_msg = "Objects are far apart";
}
return(rtn_msg);
}
rerror: 1 euc_main.cpp(34) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
thanks in advance guy ^^
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|