2.4. Another C++ Program: Adding Integers

Our next program obtains two integers typed by a user at the keyboard, computes the sum of these values and outputs the result using std::cout. Figure 2.5 shows the program and sample inputs and outputs. In the sample execution, we highlight the user’s input in bold. The program begins execution with function main (line 6). The left brace (line 7) begins main’s body and the corresponding right brace (line 22) ends it.

 1   // Fig. 2.5: fig02_05.cpp 2   // Addition program that displays the sum of two integers. 3   #include <iostream> // allows program to perform input and output 4  5   // function main begins program execution 6   int main() 7   { 8      // variable declarations ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.