Page 1 of 1

STEP in C++

Posted: May 6th, 2004, 12:41 am
by ccb056
I know that when using this code:

Code: Select all

x++;
that it increases x by 1, but what code would I use to increase x by 10, or by 0.1?

Posted: May 6th, 2004, 12:46 am
by Smartweb
x *= 10, x *= 0.1.

For the second to work x has to be a double.

Posted: May 6th, 2004, 1:10 am
by ccb056
i don't understand, where would I place that code

would I replace

Code: Select all

x++;
with

Code: Select all

x *= 10;
to increase by a factor of 10?

Posted: May 6th, 2004, 1:11 am
by Smartweb
right

Posted: May 6th, 2004, 1:13 am
by ccb056
so, if C was a constant, could I use:

Code: Select all

x *=0.1*C;

Posted: May 6th, 2004, 1:17 am
by ccb056
i have used your code, and my output is always zero for this program

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*=0.1*C;
}
return 0;
}

Posted: May 6th, 2004, 1:20 am
by Smartweb
I'm not a C++ expert. Often C++ doesn't do quite as you like it to.

Posted: May 6th, 2004, 1:21 am
by ccb056
ha, could you do what I'm trying to do in c++ in VB?

Posted: May 6th, 2004, 1:24 am
by Smartweb
The result would be more predictable, but it woudl take a little bit longer.

Posted: May 6th, 2004, 1:25 am
by Tebow2000
lol he probably could

Posted: May 6th, 2004, 1:28 am
by ccb056
Smartweb wrote:The result would be more predictable, but it woudl take a little bit longer.
that is why C++ > VB

Posted: May 6th, 2004, 1:41 am
by Smartweb
VB's advantage is that the result is predictable. And GUI's are a lot easier.

Posted: May 6th, 2004, 1:44 am
by ccb056
but c++ has faster/more efficent code and is better for a heavy math environment

Posted: May 6th, 2004, 1:47 am
by Smartweb
I like C++'s portability more than anything. I can write a program in Windows that I can compile in Linux with no changes.

Posted: May 6th, 2004, 1:49 am
by ccb056
and there are free compilers you can get for c++ legally

Posted: May 6th, 2004, 1:57 am
by ccb056
here is the code for increasing x by y

Code: Select all

x += y;