Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,254 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,167 people online right now. Registration is fast and FREE... Join Now!




cos theta

 
Reply to this topicStart new topic

cos theta

1cookie
post 11 Mar, 2008 - 03:16 AM
Post #1


D.I.C Head

Group Icon
Joined: 19 Oct, 2006
Posts: 96


My Contributions


hi


CODE



#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

float u[3], v[3], num, denom, dot_prod3;
double cos_theta, angle_radians, theta;
float pi = 3.141592653589;

//define two vectors, and the dot product
int i, j, n = 4;
int main(){

    for(j = 1; j < n; j++){
        // get x vector components
        cout<< "u_"<< j <<"= ? " <<flush;
        cin >> u[j];
        // get y vector components
        cout<< "v_"<< j <<"= ? " <<flush;
        cin >> v[j];
    }

num = (u[1] * v[1]) + (u[2] * v[2]) + (u[3] * v[3]);
denom = (sqrt((u[1] * u[1]) + (u[2] * u[2]) + (u[3] * u[3])))*
(sqrt((v[1] * v[1]) + (v[2] * v[2]) + (v[3] * v[3])));

cos_theta = num/denom;
angle_radians = acos(cos_theta);
theta = (angle_radians * 180)/pi;

cout<<setprecision(2);
cout <<"Angle is: "<< theta <<" degrees approx"<<endl;
    
if(fabs(cos_theta) <= pow((float 10 , -6))
cout<<"vectors are orthogonal"<<endl;

cout<<"\n";

return 0;
}




It's a syntax error: cpp(35) : error C2143: syntax error : missing ')' before 'constant', on line 35 in my compiler, I've tried various ways of using parenthesis to no avail!!


help appreciated.





User is offlineProfile CardPM

Go to the top of the page

aj32
post 11 Mar, 2008 - 03:48 AM
Post #2


D.I.C Addict

Group Icon
Joined: 30 Aug, 2007
Posts: 577



Thanked 2 times

Dream Kudos: 675
My Contributions


It seems that this part of your program if(fabs(cos_theta) <= pow((float 10 , -6)) needs to be changed to if(fabs(cos_theta) <= pow( 10 , -6)) to have the program compile. First, there was a ) missing at the end of the if() statment, also, using a parenthesis in a statement makes the compiler think that you only put one argument into the function, and the pow() function takes 2 arguments.

Hope this helps smile.gif
User is offlineProfile CardPM

Go to the top of the page

red_4900
post 11 Mar, 2008 - 03:49 AM
Post #3


Code Dreamers

****
Joined: 22 Feb, 2008
Posts: 791



Thanked 10 times
My Contributions


I think you're missing something :
CODE
if(fabs(cos_theta) <= pow(10 , -6))


This post has been edited by red_4900: 11 Mar, 2008 - 03:54 AM
User is offlineProfile CardPM

Go to the top of the page

1cookie
post 11 Mar, 2008 - 05:12 AM
Post #4


D.I.C Head

Group Icon
Joined: 19 Oct, 2006
Posts: 96


My Contributions


QUOTE(red_4900 @ 11 Mar, 2008 - 04:49 AM) *

I think you're missing something :
CODE
if(fabs(cos_theta) <= pow(10 , -6))




ive tried changing the parenthesis but still can't get it to run!!



ta
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 11 Mar, 2008 - 05:36 AM
Post #5


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


they gave you the answer:
cpp
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

float u[3], v[3], num, denom, dot_prod3;
double cos_theta, angle_radians, theta;
float pi = 3.141592653589;

//define two vectors, and the dot product
int i, j, n = 4;
int main(){

for(j = 1; j < n; j++){
// get x vector components
cout<< "u_"<< j <<"= ? " <<flush;
cin >> u[j];
// get y vector components
cout<< "v_"<< j <<"= ? " <<flush;
cin >> v[j];
}

num = (u[1] * v[1]) + (u[2] * v[2]) + (u[3] * v[3]);

denom = (sqrt((u[1] * u[1]) + (u[2] * u[2]) + (u[3] * u[3])))*
(sqrt((v[1] * v[1]) + (v[2] * v[2]) + (v[3] * v[3])));

cos_theta = num/denom;
angle_radians = acos(cos_theta);
theta = (angle_radians * 180)/pi;

cout<<setprecision(2);
cout <<"Angle is: "<< theta <<" degrees approx"<<endl;

if(fabs(cos_theta) <= pow(10 , -6))
cout<<"vectors are orthogonal"<<endl;

cout<<"\n";

return 0;
}
User is offlineProfile CardPM

Go to the top of the page

1cookie
post 11 Mar, 2008 - 05:47 AM
Post #6


D.I.C Head

Group Icon
Joined: 19 Oct, 2006
Posts: 96


My Contributions


QUOTE(NickDMax @ 11 Mar, 2008 - 06:36 AM) *

they gave you the answer:
cpp
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

float u[3], v[3], num, denom, dot_prod3;
double cos_theta, angle_radians, theta;
float pi = 3.141592653589;

//define two vectors, and the dot product
int i, j, n = 4;
int main(){

for(j = 1; j < n; j++){
// get x vector components
cout<< "u_"<< j <<"= ? " <<flush;
cin >> u[j];
// get y vector components
cout<< "v_"<< j <<"= ? " <<flush;
cin >> v[j];
}

num = (u[1] * v[1]) + (u[2] * v[2]) + (u[3] * v[3]);

denom = (sqrt((u[1] * u[1]) + (u[2] * u[2]) + (u[3] * u[3])))*
(sqrt((v[1] * v[1]) + (v[2] * v[2]) + (v[3] * v[3])));

cos_theta = num/denom;
angle_radians = acos(cos_theta);
theta = (angle_radians * 180)/pi;

cout<<setprecision(2);
cout <<"Angle is: "<< theta <<" degrees approx"<<endl;

if(fabs(cos_theta) <= pow(10 , -6))
cout<<"vectors are orthogonal"<<endl;

cout<<"\n";

return 0;
}





hi i run the above and i get: 9_6.cpp(36) : error C2668: 'pow' : ambiguous call to overloaded function



blink.gif







User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 11 Mar, 2008 - 06:34 AM
Post #7


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


confused.gif I don't get that... well one thing you can do is just get ride of the need for pow()...

replace pow(10, -6) with 0.000001... you can even use:
const int tolerance = 0.000001;

User is offlineProfile CardPM

Go to the top of the page

1cookie
post 11 Mar, 2008 - 06:38 AM
Post #8


D.I.C Head

Group Icon
Joined: 19 Oct, 2006
Posts: 96


My Contributions


QUOTE(NickDMax @ 11 Mar, 2008 - 07:34 AM) *

confused.gif I don't get that... well one thing you can do is just get ride of the need for pow()...

replace pow(10, -6) with 0.000001... you can even use:
const int tolerance = 0.000001;



that's great thanks.....


smile.gif
User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 11 Mar, 2008 - 06:51 AM
Post #9


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


From the MSDN Visual C++ Developer Center: Error Code C2668

Example :
CODE

// C2668e.cpp
#include <math.h>
int main() {
   pow(9,9);   // C2668
   pow((double)9,9);   // OK
}




This error can occur because the pow(int, int) was removed from math.h in the CRT.
User is offlineProfile CardPM

Go to the top of the page

1cookie
post 12 Mar, 2008 - 12:29 AM
Post #10


D.I.C Head

Group Icon
Joined: 19 Oct, 2006
Posts: 96


My Contributions


QUOTE(letthecolorsrumble @ 11 Mar, 2008 - 07:51 AM) *

From the MSDN Visual C++ Developer Center: Error Code C2668

Example :
CODE

// C2668e.cpp
#include <math.h>
int main() {
   pow(9,9);   // C2668
   pow((double)9,9);   // OK
}




This error can occur because the pow(int, int) was removed from math.h in the CRT.



thanks LTCR....


wink2.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 10:45PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month