Input-Output Example


Program Listing

IOExample.cpp

/************************************************************************
*                                                                       *
*   Program:    IOExample                                               *
*                                                                       *
*   Purpose:    This program will read three integers and print their   *
*               values                                                  *
*                                                                       *
************************************************************************/

#include <iostream>
#include <string>

using namespace std;

int main() {

//  Declare the integers

    int a, b, c;            

//  Read and print a

    cout << "Enter the value of a:  " << flush;
    cin >> a;
    cout << "a = " << a << endl;

//  Read and print b

    cout << "Enter the value of b:  " << flush;
    cin >> b;
    cout << "b = " << b << endl;

//  Read and print c

    cout << "Enter the value of c:  " << flush;
    cin >> c;
    cout << "c = " << c << endl;
    
    return 0;
}

Sample Run #1

Enter the value of a:  5
a = 5
Enter the value of b:  10
b = 10
Enter the value of c:  15
c = 15

Sample Run #2

Enter the value of a:  5 10 15
a = 5
Enter the value of b:  b = 10
Enter the value of c:  c = 15



Return to Lectures page


e-mail me at robbk@hsc.edu

This page was last modified on Tue Dec 7 16:04:24 1999 .

URL: http://people.hsc.edu/faculty-staff/robbk/Coms261/Examples/IOExample.html

Return to Coms 261 home page