Page 1 of 1
C++ and Order of Operations
Posted: May 5th, 2004, 10:23 pm
by ccb056
will C++ process this according to the order of operations:
Posted: May 5th, 2004, 10:29 pm
by Tebow2000
I will just do better memorizing them!
Posted: May 5th, 2004, 10:46 pm
by Smartweb
yeah, all computer languages follow order of operations.
Posted: May 5th, 2004, 10:48 pm
by ccb056
so, if I just used v*x-a+b/c it would follow order of operations on any lanyuage rather than execute from left to right?
Posted: May 5th, 2004, 10:49 pm
by Smartweb
right
Posted: May 5th, 2004, 10:52 pm
by ccb056
do they also follow the paren () rule?
Posted: May 5th, 2004, 10:52 pm
by Smartweb
Yes
Posted: May 5th, 2004, 11:05 pm
by ccb056
do you see anything wrong with this code?
Code: Select all
#include <iostream>
int main ()
{
int C=299792458;
int X=0;
int Y=0;
int V=0;
/*
V=(V1+V2)/(1+((V1*V2)/(C^2)))
*/
while (X<C)
{
V=(X+Y)/(1+((X*Y)/(C^2)));
cout<<V<<"\n";
X++;
cout<<V<<"\n";
Y++;
cout<<V<<"\n";
}
return 0;
}
Posted: May 5th, 2004, 11:09 pm
by Smartweb
Well, it'll return about a billion lines in the command line; but if that is what you intended, then yes, it will work.
Posted: May 6th, 2004, 12:17 am
by ccb056
ok, I rewrote it a little and it wont work, here is what I'm working with
Code: Select all
#include <iostream>
int main ()
{
double C=299792458;
double X=0;
double Y=0;
double V=0;
/*
V=(V1+V2)/(1+((V1*V2)/(C^2)))
*/
while (X<C)
{
cout<<"V1="<<X<<"\n";
cout<<"V="<<(X+X)/(1+((X*X)/(C^2)))<<"\n";
X++;
}
return 0;
}
The compiler (Dev-C++) says this:
line 14 invalid operands `double' and `int' to binary `operator ^'
Posted: May 6th, 2004, 12:36 am
by Smartweb
What happens if you change C^2 to C*C
Posted: May 6th, 2004, 12:37 am
by ccb056
ha, its works with c*c, bout not c^2
why did it work before with c^2 and not with the new version?
Posted: May 6th, 2004, 12:45 am
by ccb056
it's taking a while to finish processing this code:
Code: Select all
#include <iostream>
int main ()
{
double C=299792458;
double X=0;
double Y=0;
double V=0;
/*
V=(V1+V2)/(1+((V1*V2)/(C^2)))
*/
while (X<C)
{
cout<<"V1="<<X<<"\n";
cout<<"V="<<(X+X)/(1+((X*X)/(C*C)))<<"\n";
X++;
}
return 0;
}
what's funny is the two velocities in question (V1 and V2) are the same, eventually, I want to run through all combinations of V1 and V2 in steps of .1c
I need to figure out how to do the step stuff first...
after I have that info, I will migrate into a 3d graph in which I hope to find a 'cone'
I then want to find the volume and area of the cone