``````double distance (double angle, int mps, double earth_gravity)
{
double earth_distance;
double speed_sqr = mps * mps;

earth_distance = speed_sqr * sin(2*angle) / earth_gravity;
return earth_distance;
}``````

its supposed to come out at = 3831.57
intead it ends up being =3155.52

anyone know what im doing wrong?

## All 34 Replies

for what input parameters?

Ill just show you my whole program

``````#include <iostream>
#include <cmath>
using namespace std;

double angtorad (double angle, double pi);
double distance_earth (double angle, int mps, double earth_gravity);
double distance_moon (double angle, int mps, double moon_gravity);
double distance_mars (double angle, int mps, double mars_gravity);

int main ()
{

int mps;
double angle;
double pi =  3.1415927;
double earth_gravity = 9.81;
double moon_gravity = 1.62;
double mars_gravity = 3.69;

cout << " ***  Program 3 Planetary Trajectory Simulator  *** " << endl;
cout << endl;
cout << " Enter the speed of launch (mps)	";
cin >> mps;
cout << " Enter the angle of launch (degrees)	"	;
cin >> angle;
cout << endl;
cout << " You have entered " << mps << " mps for the speed and " << angle << " degrees for the angle." << endl;
cout << " " << angle << " degrees is equal to " << angtorad(angle, pi) << " radian(s)." << endl << endl << endl;
cout << " The distance traveled on Earth = " << distance_earth (angle,mps,earth_gravity) << " meters " << endl;
cout << " The distance traveled on Mars = " << distance_mars (angle,mps,mars_gravity) << " meters " << endl;
cout << " The distance traveled on The Moon = " << distance_moon (angle,mps,moon_gravity)<< " meters " << endl;

return 0;
}

double angtorad (double angle, double pi)
{
radian =  pi * (angle / 180);
}

double distance_earth (double angle, int mps, double earth_gravity)
{
double earth_distance;
earth_distance =  sin(2*angle)*(mps*mps) / earth_gravity;
return earth_distance;
}
double distance_moon (double angle, int mps, double moon_gravity)
{
double moon_distance;
moon_distance =  sin(2*angle)*(mps*mps) / moon_gravity;
return moon_distance;
}
double distance_mars (double angle, int mps, double mars_gravity)
{
double mars_distance;
mars_distance = sin(2*angle)*(mps*mps) / mars_gravity;
return mars_distance;
}``````

Return angtorad into a variable, so say `double angrad = angtorad(angle,pi);` You never actually change angle when you run your function. Use your new value in place of angle in your other functions.

is that going to fix the math problem? of why i get about 800 meters short?

I dont really understand what you're suggesting?

I didn't check your math....give it a try, as it stands you are not converting your degrees to radians (except to display it on that one line, but the next line you put the value in degrees into your function).

you call angtorad, but you do nothing with the return value except send it to the output stream. just calling your function does not change the value of angle which remains at the value your user had entered, even when you call the other functions with angle in the arguments.

On line 29 you're converting your input angle to radians TEMPORARILY to display it, but you are not storing the result value any where. As a result, when you call distance_earth(), distance_moon(), and distance_mars(), the angle is still in degrees. You must find a way to do a permanent conversion from Degrees to Radians, then send the Radians version of your angle to the other functions.

Another option is to include the conversion function call directly as an argument to the other functions.
In other words:

``````cout << " The distance traveled on Earth = " << distance_earth (angle,mps,earth_gravity) << " meters " << endl;
cout << " The distance traveled on Mars = " << distance_mars (angle,mps,mars_gravity) << " meters " << endl;
cout << " The distance traveled on The Moon = " << distance_moon (angle,mps,moon_gravity)<< " meters " << endl;``````

Would become:

``````cout << " The distance traveled on Earth = " << distance_earth (angtorad(angle,pi),mps,earth_gravity) << " meters " << endl;
cout << " The distance traveled on Mars = " << distance_mars (angtorad(angle,pi),mps,mars_gravity) << " meters " << endl;
cout << " The distance traveled on The Moon = " << distance_moon (angtorad(angle,pi),mps,moon_gravity)<< " meters " << endl;``````

Hope that helps. :)

Yeah, I know what youre talking about now but thats a problem I have to fix a little further down the road...

Right now I dont understand why "(200^2)*sin(2*35) / 9.81" dosnt equal 3831.57... I did it on the calc and it does

but when I do that same equation in my function I get 3155.52

Yeah, I know what youre talking about now but thats a problem I have to fix a little further down the road...

Right now I dont understand why "(200^2)*sin(2*35) / 9.81" dosnt equal 3831.57... I did it on the calc and it does

but when I do that same equation in my function I get 3155.52

1.) Is that 35 Degrees or Radians? It looks like Degrees to me...

There is an enormous difference between Degrees and Radians. There are 360 Degrees in a circle, but there are only 6.28 (2*PI) Radians in that same circle.

If I run your equation as stated on my calculator:
in Deg mode I get 3831.570 (which you believe to be the correct answer, it probably is)
in Rad mode I get 3155.518

Either way, your angle value in your program is being passed as Degrees which is messing up your Trig calculation (the sin() statement). The passing error must be corrected or you will continue to get invalid results.

HAHA okay, I kind of understand that now :)

thanks everyone... ill be back im sure of it :-/

Right, Because...The sin function in the math library uses radians.

``````cout << " " << angle << " degrees is equal to " << (angrad = angtorad(angle, pi)) << " radian(s)." << endl << endl << endl;
cout << " The distance traveled on Earth = " << distance_earth (angrad,mps,earth_gravity) << " meters " << endl;
cout << " The distance traveled on Mars = " << distance_mars (angrad,mps,mars_gravity) << " meters " << endl;
cout << " The distance traveled on The Moon = " << distance_moon (angrad,mps,moon_gravity)<< " meters " << endl;``````

to spell it out explicitly...

okay after figuring that out, I started a new function and ran into another problem :(

``````double height_earth (double angle ,int mps, double earth_gravity, double earthx)
{
double max_height_earth;
max_height_earth = earthx * tan(angle) - (earth_gravity*(earthx *earthx) / 2(mps*cos(angle)));
return max_height_earth;
}
``````

what does Error 1 error C2064: term does not evaluate to a function taking 1 argument mean????

okay after figuring that out, I started a new function and ran into another problem :(

``````double height_earth (double angle ,int mps, double earth_gravity, double earthx)
{
double max_height_earth;
max_height_earth = earthx * tan(angle) - (earth_gravity*(earthx *earthx) / 2(mps*cos(angle)));
return max_height_earth;
}
``````

what does `***Error 1 error C2064: term does not evaluate to a function taking 1 argument ****` mean????

Check your new call(s). You probably forgot some required arguments.

Make sure the argument counts in those calls match the parameter counts in the appropriate function definitions.

How would you write out this equation so that a c++ compiler will take it:

y = xtan(angle) - Gx^2 /
2(speed*cos(angle))^2

Hope that is understandable

How would you write out this equation so that a c++ compiler will take it:

y = xtan(angle) - Gx^2 /
2(speed*cos(angle))^2

Hope that is understandable

I suggest you:
1.) try it

I have tried it and he will need that equation too for a later part of the problem. I figured I might as well go ahead and ask it so he won't have to worry about it.

haha are u in Dr. Keens CS 115?

``````double height_earth (double angle ,int mps, double earth_gravity, double earthx)
{
double max_height_earth;
max_height_earth = earthx * tan(angle) - (earth_gravity*(earthx *earthx) / 2(mps*cos(angle)));
return max_height_earth;
}``````

is that equation for my program

I cant get it to work yet though :(

I have tried it and he will need that equation too for a later part of the problem. I figured I might as well go ahead and ask it so he won't have to worry about it.

I understand, my apologies. :)

I've been checking my calls and yet to find any thing that I notice... this is by far the longest program that I have done...

Do you think you could tell me where the call error is that is giving me the Error 1 error C2064: term does not evaluate to a function taking 1 argument ??

``````#include <iostream>
#include <cmath>
using namespace std;

double angtorad (double angle, double pi);
double distance_earth (double angle, int mps, double earth_gravity);
double distance_moon (double angle, int mps, double moon_gravity);
double distance_mars (double angle, int mps, double mars_gravity);
double height_earth (double angle, int mps, double earth_gravity, double earthx);
int main ()
{

int mps;
double angle;
double pi =  3.1415927;
double earth_gravity = 9.81;
double moon_gravity = 1.62;
double mars_gravity = 3.69;

cout << " ***  Program 3 Planetary Trajectory Simulator  *** " << endl;
cout << endl;
cout << " Enter the speed of launch (mps)	";
cin >> mps;
cout << " Enter the angle of launch (degrees)	"	;
cin >> angle;
cout << endl;
cout << " You have entered " << mps << " mps for the speed and " << angle << " degrees for the angle." << endl;
cout << " " << angle << " degrees is equal to " << angtorad(angle, pi) << " radian(s)." << endl << endl << endl;
cout << " The distance traveled on Earth = " << distance_earth (angtorad(angle,pi),mps,earth_gravity) << " meters " << endl;
cout <<"				Max Height = " << height_earth (angtorad(angle,pi), mps, earth_gravity, earthx) <<

cout << " The distance traveled on Mars = " << distance_mars (angtorad(angle,pi),mps,mars_gravity) << " meters " << endl;

cout << " The distance traveled on The Moon = " << distance_moon (angtorad(angle,pi),mps,moon_gravity)<< " meters " << endl;

return 0;
}

double angtorad (double angle, double pi)
{
radian =  pi * (angle / 180);
}

double distance_earth (double angle, int mps, double earth_gravity)
{
double earth_distance;
earth_distance =  sin(angle + angle)*(mps*mps) / earth_gravity;
return earth_distance;
}
double distance_moon (double angle, int mps, double moon_gravity)
{
double moon_distance;
moon_distance =  sin(angle + angle)*(mps*mps) / moon_gravity;
return moon_distance;
}
double distance_mars (double angle, int mps, double mars_gravity)
{
double mars_distance;
mars_distance = sin(angle + angle)*(mps*mps) / mars_gravity;
return mars_distance;
}
double height_earth (double angle, int mps, double earth_gravity, double earthx)
{
double max_height_earth;
max_height_earth = earthx * tan(angle) - (earth_gravity*(earthx *earthx)) / 2(mps*cos(angle));
return max_height_earth;
}``````

I've done some looking, I don't see anything glaring. Without having a line number to start at it's really hard to say...

I don't remember the necessary equations ATM, so double check your calculations on lines 54, 60, 66, and 72. I suspect there might be some issues with parentheses and order of operations there...

the error is on line 72... sorry should have specified

im still looking and still dont know whats happening :(

lol I need to quit while I'm ahead, im just not cut out for comp sci

should be `2*(mps*cos(angle)));` in the height_earth function (you left out the multiplication sign)

Like anything else, if this is something you want to be doing you need to work hard at it.

haha wow... after fixing that multiplication sign, I got a doozie

Error 3 error LNK2019: unresolved external symbol "double __cdecl height_earth(double,int,double,double)" (?height_earth@@YANNHNN@Z) referenced in function _main program3.obj

lol what exactly does that mean?

nevermind found it.... I think

For some reason I keep getting uninitialized local variables for mine. Wish I could figure that part out. I think if I could I could the rest pretty quickly.

haha I think I'm almost done but I need just a little more help...

on line 20 i get

Warning1warning C4700: uninitialized local variable 'mps' used
Warning1warning C4700: uninitialized local variable 'angle' used

``````#include <iostream>
#include <cmath>
using namespace std;

double angtorad (double angle, double pi);
double distance_earth (double angle, int mps, double earth_gravity);
double distance_moon (double angle, int mps, double moon_gravity);
double distance_mars (double angle, int mps, double mars_gravity);
double height_earth (double angle, int mps, double earth_gravity, double earthx);
double height_mars (double angle, int mps, double earth_gravity, double marsx);
int main ()
{

int mps;
double angle;
double pi =  3.1415927;
double earth_gravity = 9.81;
double moon_gravity = 1.62;
double mars_gravity = 3.69;
double earthx = (distance_earth(angle, mps, earth_gravity));
double marsx =  (distance_mars (angle, mps, mars_gravity));
double moonx =  (distance_moon (angle, mps, moon_gravity));``````

what do i need to change?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.