May 25, 2011 at 4:00pm May 25, 2011 at 4:00pm UTC
i am trying to write a program that could output the magnitudes of a 2-dimensional vector and a 3-dimensional vector, however im stuck at this point
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
using std::cout;
using std::endl;
#include <cmath>
double magnitude(double x, double y);
double magnitude(double x, double y, double z);
int main() {
double mag2D, mag3D;
mag2D = magnitude(3,4);
mag3D = magnitude(3,4,5);
cout<<"magnitude of 2D vector = " << mag2D << endl;
cout<<"magnitude of 3D vector = " << mag3D << endl;
return 0;
}
can anyone help me?
Last edited on May 25, 2011 at 4:00pm May 25, 2011 at 4:00pm UTC
May 25, 2011 at 4:37pm May 25, 2011 at 4:37pm UTC
You mean return sqrt(x*x+y*y);
?
May 25, 2011 at 6:30pm May 25, 2011 at 6:30pm UTC
yes pretty much but how do I include that into the program?
also I dont understand y the current on always gives me errors
thx!
May 26, 2011 at 3:37pm May 26, 2011 at 3:37pm UTC
hi yeh i fixed it thx!! (silly rookie error, missed a semi colon )
however just one last question what does the sqrt function does?
could i possibly write a function without using it?
May 26, 2011 at 3:41pm May 26, 2011 at 3:41pm UTC
sqrt(x) is short for Square Root of x. You can write a function any way you like, it's just this specific function that you will want to use the sqrt() function for.
Last edited on May 26, 2011 at 3:42pm May 26, 2011 at 3:42pm UTC