Simple math in C++: Difference between revisions

wikademia>Giawa
Created page
 
wikademia>Chyld989
Line 20: Line 20:


<code><pre>
<code><pre>
int my_result;
int myResult;
my_result = 5 + 6;  // A value of 11 will be stored into the integer my_result
myResult = 5 + 6;  // A value of 11 will be stored into the integer my_result
</pre></code>
</pre></code>


Line 28: Line 28:
<code><pre>
<code><pre>
int five=5, six=6, twelve=12;
int five=5, six=6, twelve=12;
float pi=3.14, my_result;
float pi=3.14, myResult;
my_result = (float)six * pi + (float)twelve;
myResult = (float)six * pi + (float)twelve;
my_result = my_result - (float)five;
myResult = myResult - (float)five;
</pre></code>
</pre></code>


Line 38: Line 38:


<code><pre>
<code><pre>
my_result = my_result+5;
myResult = myResult+5;
my_result += 5;
myResult += 5;
my_result = my_result-5;
myResult = myResult-5;
my_result -= 5;
myResult -= 5;
my_result = my_result*5;
myResult = myResult*5;
my_result *= 5;
myResult *= 5;
my_result = my_result/5;
myResult = myResult/5;
my_result /= 5;
myResult /= 5;
</pre></code>
</pre></code>