Public paste
asdfasdfasdf
By: asdfasdfasdf | Date: Nov 17 2006 18:03 | Format: C++ | Expires: never | Size: 1.53 KB | Hits: 762

  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 total, average, highest;
  18.      
  19.      obtain(temp, NUM_DAYS);
  20.  
  21.      total = find_average(temp, NUM_DAYS);
  22.      
  23.      average = total / NUM_DAYS;
  24.      
  25.      highest = getHighest(temp, NUM_DAYS);
  26.      
  27.      cout << fixed << showpoint << setprecision(1);
  28.      cout<<"average = " << average;
  29.      cout<<"nhighest = "<< highest;
  30.      
  31.     system("PAUSE");
  32.     return 0;
  33. }
  34.  
  35. void obtain()
  36. {
  37.          
  38.      const int NUM_DAYS = 28;
  39.      double temp[NUM_DAYS];
  40.      double total, average, highest;
  41.      
  42.      
  43.      for (int count = 0; count < NUM_DAYS; count++)
  44.      {
  45.          cout << "Enter the temp for each day ";
  46.          cout << (count + 1) << ": ";
  47.          cin >> temp[count];
  48.      }
  49.      
  50.       return temp[count];      
  51.    
  52. }
  53. double find_average(double array[], int size)
  54. {
  55.        double total = 0;
  56.        for (int count = 0; count < size; count++)
  57.        total += array[count];
  58.        return total;
  59.        
  60. }
  61.        
  62. double getHighest(double array[], int size)
  63. {
  64.        double highest;
  65.        
  66.        highest = array[0];
  67.        for (int count = 1;count < size;count++)
  68.        {
  69.            if (array[count] > highest)
  70.            highest = array[count];
  71.        }
  72.        
  73.        return highest;
  74.        }
  75.  
Latest pastes
7 hours ago
20 hours ago
20 hours ago
1 days ago
1 days ago