COS()

Started by
1 comment, last by ironbox 19 years, 7 months ago
i making a thign for proj. motion but i can't get cos() to work. heres the code. In addtion to the cos() problem, im wanting to make an x,y graph. Can someone make a simple function to input x,y corrds and it will clear the screen and put a * or something at x,y. I know about goto(x,y), or something, but have never used it, i don't know what header file goto(x,y) is in either. #include <iostream> #include <stdlib.h> #include <cmath> using namespace std; ////////////////////////////////////// // Variables- // theta = angle // vo = original velocity // vox = original velocity along x // voy = original velocity along y // t = time // dx = displacement of x // dy = displacement of y // ax = acceleration along x // ay = acceleration along y // vfy = a velocity along y ////////////////////////////////////// double theta, vo, vox, voy, t=0, dx=0, dy=0, ax=0, ay=0; ////////////////////////////////////// // Function Prototypes ////////////////////////////////////// void GetValues(); void SetVelocities(); int main() { GetValues(); SetVelocities(); system("PAUSE"); return 0; } void GetValues() { do { cout << "What is the angle at which the projectile "; cout << "is launched? 0-90" << endl; cin >> theta; } while((theta > 90) || (theta < 0)); cout << "What is the velocity at which the "; cout << "projectile is launched? m/s" << endl; cin >> vo; } void SetVelocities() { cout << "theta = " << theta << endl; vox = vo*(cos(theta)); cout << "theta = " << theta << endl; cout << "vo = " << vo << endl; cout << "vox = " << vox << endl; }
Advertisement
cos accepts radians as the argument. are you passing radians or degrees? from you code, it looks like degrees.

to convert from degrees to radians:

float radians = degrees * PI/180.0f;


-me
thanks, ill try it

This topic is closed to new replies.

Advertisement