Performing and Displaying a Calculation
Now you are ready to move ahead and enhance the example you worked with in the last lesson. This time, you are replacing a line, not adding one. Have a look at Listing 3.1.
Listing 3.1. The Example Performs a Calculation
1: #include <iostream> 2: 3: using namespace std; 4: 5: int main(int argc, char* argv[]) 6: { *7: // Should print the number 6 *8: cout << ((6/2)+3) << endl; 9: return 0; 10: } |
This program displays the value 6, which is the result of calculating ((6/2)+3). |
Expressions
((6/2)+3) is an example of an expression. In this case, the expression uses literal numbers, operators (/ and +), and ...
Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.