Code help, language discussions, and software development advice.
ccb056
Site Administrator
Posts: 1003 Joined: January 14th, 2004, 11:36 pm
Location: Texas
Post
by ccb056 » May 5th, 2004, 10:23 pm
will C++ process this according to the order of operations:
Tebow2000
Registered User
Posts: 1099 Joined: January 19th, 2004, 7:56 am
Location: New Orleans, Louisiana
Post
by Tebow2000 » May 5th, 2004, 10:29 pm
I will just do better memorizing them!
Redcode Hosting
redcodehosting.com | Unix Shared Hosting | sales[aT]redcodehosting[dOt]com
Smartweb
Registered User
Posts: 622 Joined: January 15th, 2004, 2:11 am
Post
by Smartweb » May 5th, 2004, 10:46 pm
yeah, all computer languages follow order of operations.
ccb056
Site Administrator
Posts: 1003 Joined: January 14th, 2004, 11:36 pm
Location: Texas
Post
by ccb056 » May 5th, 2004, 10:48 pm
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?
Smartweb
Registered User
Posts: 622 Joined: January 15th, 2004, 2:11 am
Post
by Smartweb » May 5th, 2004, 10:49 pm
right
ccb056
Site Administrator
Posts: 1003 Joined: January 14th, 2004, 11:36 pm
Location: Texas
Post
by ccb056 » May 5th, 2004, 10:52 pm
do they also follow the paren () rule?
Smartweb
Registered User
Posts: 622 Joined: January 15th, 2004, 2:11 am
Post
by Smartweb » May 5th, 2004, 10:52 pm
Yes
ccb056
Site Administrator
Posts: 1003 Joined: January 14th, 2004, 11:36 pm
Location: Texas
Post
by ccb056 » May 5th, 2004, 11:05 pm
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;
}
Smartweb
Registered User
Posts: 622 Joined: January 15th, 2004, 2:11 am
Post
by Smartweb » May 5th, 2004, 11:09 pm
Well, it'll return about a billion lines in the command line; but if that is what you intended, then yes, it will work.
ccb056
Site Administrator
Posts: 1003 Joined: January 14th, 2004, 11:36 pm
Location: Texas
Post
by ccb056 » May 6th, 2004, 12:17 am
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 ^'
Smartweb
Registered User
Posts: 622 Joined: January 15th, 2004, 2:11 am
Post
by Smartweb » May 6th, 2004, 12:36 am
What happens if you change C^2 to C*C
ccb056
Site Administrator
Posts: 1003 Joined: January 14th, 2004, 11:36 pm
Location: Texas
Post
by ccb056 » May 6th, 2004, 12:37 am
ha, its works with c*c, bout not c^2
why did it work before with c^2 and not with the new version?
ccb056
Site Administrator
Posts: 1003 Joined: January 14th, 2004, 11:36 pm
Location: Texas
Post
by ccb056 » May 6th, 2004, 12:45 am
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