I am having a problem with the results that I am getting when I run my program, according to the math i wrote in the program when I enter these results
object's x co-ord = 0
object's y cor-ord = 0
object's heading = 45 degrees
object's distance travelled = 1
then
object's new x,y position should display as (0.5,0.5) but everytime i run it with those values i get (0,1) and I am not sure what is wrong. All help is appreciated.
#include <iostream>
using namespace std;
int main()
{
double x1;
double y1;
int heading;
double distance;
double xHeadingRatio;
double yHeadingRatio;
double x2 = 0;
double y2 = 0;
cout << "Enter object's x co-ordinate: ";
cin >> x1;
cout << "\n";
cout << "Enter object's y co-ordinate: ";
cin >> y1;
cout << "\n";
cout << "Enter object's heading (degrees): ";
cin >> heading;
cout << "\n";
cout << "Enter object's distance travelled: ";
cin >> distance;
if (heading == 0)
{
y2 = y1 + distance;
}
if (heading == 90)
{
x2 = x1 + distance;
}
if (heading == 180)
{
y2 = y1 - distance;
}
if (heading == 270)
{
x2 = x1 - distance;
}
if (heading > 0 && heading < 90)
{
xHeadingRatio = heading / 90;
yHeadingRatio = 1 - xHeadingRatio;
x2 = distance * xHeadingRatio;
y2 = distance * yHeadingRatio;
}
if (heading > 90 && heading < 180)
{
// math not finished
}
if (heading > 180 && heading < 270)
{
// math not finished
}
if (heading > 270 && heading < 360)
{
// math not finished
}
cout << "\n";
cout << "The new x and y co-ordinates are (";
cout << x2;
cout << ",";
cout << y2;
cout << ")";
cout << "\n";
system("PAUSE");
}