Advertisement
rnlewis

Untitled

Oct 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1.  
  2. /*     ____   __     __
  3.         /   /   \  /   \
  4.        /   /      /
  5.       /    \___/  \___/
  6.  
  7. Date: 10/19/17
  8.  
  9. Name: Rebecca Lewis
  10.  
  11. Project Description: Hw #7 Problem 3;
  12. Inputs:
  13.  
  14. Outputs:
  15. */
  16. //*************************************************************
  17.  
  18. #include <iostream>
  19. #include <string>
  20. #include <cmath>
  21. #include <iomanip>
  22.  
  23. using namespace std; //introduces namespace std
  24.  
  25.  
  26. //Function Prototypes
  27. double Average(double [], const int);
  28.  
  29. int main (void)
  30. {
  31.     int num_terms=0, x, above_average=0, below_average=0;
  32.     const int size=100;
  33.     double A[size], average;
  34.    
  35.     cout<<"Please enter the scores (use a negative number to indicate all scores are entered): " <<endl;
  36.        
  37.     do
  38.     {
  39.         x=1;
  40.         for(int i=0; i<=num_terms; num_terms++)
  41.             {
  42.                 cin>>A[num_terms];
  43.                 if(num_terms<0)
  44.                     {
  45.                         x=-1;
  46.                         A[num_terms]-=A[num_terms-1];
  47.                     }
  48.             }      
  49.     }
  50.     while(x>0);
  51.     average=Average(A,num_terms);
  52.     if(int i=0; A[i]>=average; above_average++)
  53.         {
  54.            
  55.             above_average++;   
  56.         }
  57.     if(int i=0; A[i]<average;below_average++)
  58.         {
  59.             below_average++;
  60.         }
  61.    
  62.    
  63.    
  64.     cout<<"There are" <<above_average <<"terms above or equal to the array average."<<endl;
  65.     cout<<"There are" <<below_average <<"terms below the array average."<<endl;
  66.     return 0;
  67. }
  68.  
  69. //Function allows each element in an array to be added and stored as
  70. //the variable sum.
  71. double Average(double A[], const int size)
  72.     { int sum, average;
  73.             for(double i=0; i<size; i++)
  74.             sum+=A[i];
  75.             average=sum/size;
  76.            
  77.         return average;
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement