home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-3.ZIP / EXAMPLES.ZIP / INTRO18.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  692b  |  26 lines

  1. // INTRO18.CPP--Example from Chapter 3, "An Introduction to C++"
  2.  
  3. #include <iostream.h>
  4.  
  5. int main()
  6. {
  7.    int  number= 1;         // Number entered by user
  8.    int  total = 0;         // Total of numbers entered so far
  9.    int  count = 0;         // Count of numbers entered
  10.  
  11.    cout << "\nEnter a number, 0 to quit:\n";
  12.    while (number != 0)
  13.    {
  14.       cin >> number;       // Enter an integer only
  15.       if(number == 0)
  16.          cout << "Thank you. Ending routine.\n";
  17.       else count++;
  18.       total += number;
  19.    }
  20.    cout << "Total is " << total << '\n';
  21.    cout << "Count is " << count << '\n';
  22.    cout << "Average is " <<  total / count << '\n';
  23.  
  24.    return 0;
  25. }
  26.