double a = 50.0;// declare a value with a floating point and
// assign the value 50 to itdouble b = 2.0;
double c;
c = a + b; // assign to the variable c sum of variables
// a and b. Now the value is equal to 52. Like after
// any other instruction put a semicolon (“;”)
c = a - b; // diminution, c = 48
c = a*b; // multiplication, c = 100
c = a / b; // division, c = 25
c = (a + b)*a; // place the operations that should be performed
// first inside the brackets. In our case
// first we get the sum of a and b
// after that this sum will be multiplied by a and assigned to c
c = (a + b) / (a - b); // if there are several operations in brackets,
// they will be performed
c = a + b*3.0; // according to mathematic rules first you will get
// multiplication b and 3, and then the sum
如果需要用某个变量执行一项运算,并分配一个结果给它,例如加 5,可以采用以下方式之一:
int a = 5;
a = a + 5; // add 5
a += 5; // analogous
a = a*5;a *= 5; // multiply a by 5 and assign to it
a /= 5; // divide and assign
如要加 1 或减 1,用以下方法:
int a = 5;
a++; // add1, it is called increment
а--; // subtract 1, it is decrement
int a = 50;
int b = 100;
string str1 = "a + b =";
str1 += a + b; // now str1 = "a + b = 150" // now use the variable str1 as // a first parameterMessageBox(str1, "a + b = ?");