A SAMPLE C++ PROGRAM


The following is a sample C++ program.

// MultiplyIntegers.cpp
/* Program asks user to input 2 integers from the keyboard.
    Program then multiplies the 2 integers to find the product.
    The result is then displayed on the screen.
    */

#include <iostream>
using namespace std;

int main( )
{
    int number1, number2,     // 2 integer variables to store the 2 integers
          product;                       // an integer variable to store the product

    // Sent the following prompt to the screen.
    cout << "Type 2 integers separated by a blank space & press the ENTER key: ";

    // Accept 2 integers (separated by a space) typed from the keyboard.
    cin >> number1 >> number2;

    // Compute and store the product
    product = number1 * number2;        // Use * to denote multiplication

    // Display the result on the screen.
    // use endl ("end line") to force a break in the line.
    cout << "The product is: " << product << endl;

    return 0;
}