Using the if Statement

The following example (Fig. 2.10) uses six if statements to compare two numbers input by the user. If the condition in any of these if statements is satisfied, the output statement associated with that if statement is executed.

 1   // Fig. 2.13: fig02_13.cpp 2   // Comparing integers using if statements, relational operators 3   // and equality operators. 4   #include <iostream> // allows program to perform input and output 5  6   using std::cout; // program uses cout  7   using std::cin; // program uses cin   8   using std::endl; // program uses endl  9 10   // function main begins program execution11   int main()12   {13      int number1 = 0; // first integer to compare (initialized to ...

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.