home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9203 / borhot / strstr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-24  |  1.3 KB  |  42 lines

  1. /* ------------------------------------------------------ */
  2. /*                      STRSTR.CPP                        */
  3. /* This program takes the average of numbers entered at   */
  4. /* the command line.                                      */
  5. /*              (c) 1991 Borland International            */
  6. /*                   All rights reserved.                 */
  7. /* ------------------------------------------------------ */
  8. /*            veröffentlicht in DOS toolbox 3'92          */
  9. /* ------------------------------------------------------ */
  10.  
  11. #include <strstream.h>
  12. #include <string.h>
  13.  
  14. /* ------------------------------------------------------ */
  15.  
  16. main( int argc, char *argv[] )
  17. {
  18.   unsigned u;
  19.   double total = 0, average = 0, d = 0;
  20.  
  21.   if ( argc == 1 ) {
  22.                     // Not enough command line parameters!
  23.     cout << endl
  24.          << "Usage <filename> float float ...." << endl;
  25.     return 1;
  26.   }
  27.  
  28.   for ( u = 1; u < argc; ++u ) {
  29.     istrstream istr( argv[u], strlen(argv[u]) );
  30.     istr >> d;
  31.     total += d;
  32.   }
  33.  
  34.   average = total / (argc - 1);
  35.   cout.setf( ios::fixed, ios::floatfield );
  36.   cout << endl << "AVERAGE = " << average << endl;
  37.   return 0;
  38. }
  39. /* ------------------------------------------------------ */
  40. /*                   Ende von STRSTR.CPP                  */
  41.  
  42.