Public paste
jew work
By: jews | Date: Nov 17 2006 18:10 | Format: C++ | Expires: never | Size: 1.4 KB | Hits: 1449

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cmath>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. void obtain(double[], int);
  8. double find_average(double[], int);
  9. double getHighest(double[], int);
  10.  
  11.  
  12. int main()
  13. {
  14.      
  15.      const int NUM_DAYS = 28;
  16.      double temp[NUM_DAYS];
  17.      double average, highest;
  18.      
  19.      obtain(temp, NUM_DAYS);
  20.  
  21.      average = find_average(temp, NUM_DAYS);
  22.    
  23.      
  24.      highest = getHighest(temp, NUM_DAYS);
  25.      
  26.      cout << fixed << showpoint << setprecision(1);
  27.      cout<<"average = " << average;
  28.      cout<<"nhighest = "<< highest;
  29.      
  30.     system("PAUSE");
  31.     return 0;
  32. }
  33.  
  34. void obtain(double temp[], int NUM_DAYS)
  35. {
  36.          
  37.      
  38.      for (int count = 0; count < NUM_DAYS; count++)
  39.      {
  40.          cout << "Enter the temp for each day ";
  41.          cout << (count + 1) << ": ";
  42.          cin >> temp[count];
  43.      }
  44.            
  45.    
  46. }
  47. double find_average(double array[], int size)
  48. {
  49.        double total = 0;
  50.        for (int count = 0; count < size; count++)
  51.        total += array[count];
  52.        return total / size;
  53.        
  54. }
  55.        
  56. double getHighest(double array[], int size)
  57. {
  58.        double highest;
  59.        
  60.        highest = array[0];
  61.        for (int count = 1;count < size;count++)
  62.        {
  63.            if (array[count] > highest)
  64.            highest = array[count];
  65.        }
  66.        
  67.        return highest;
  68.        }
  69.  
  70.