[ create a new paste ] login | about

Link: http://codepad.org/X6u0Noqn    [ raw code | output | fork ]

C++, pasted on May 6:
#include <iostream>
      using namespace std;

      void displayTitle ()
      {
              cout << "Calculate the Average Age of Parents seeking Invetro" << endl;
       }                
       double ave (double array[], int asize)
      {
              double average;
              double sum;
              for (int i = 0; i < asize; i++)
                {
                  sum += array[i];
               }
              average=sum/asize;
              return ( average );
      }
      int main ()
              {
              displayTitle ();
              double ParentsAge[10], age1, average; //declaring array as integer
              int i, sum; //declaring age1 sum and integer
              sum = 0;
              for (int i = 0; i < 10; i++)  //for loop to keep count
              {
                      cout << "Enter 10 parents age: " << ( i + 1 ) << endl;
                      cin >> age1;  //input of ages
                      if (age1 != 0) {
                              ParentsAge[i] =age1;  //adding ages together
                      }
                      else {
                              cout << "Enter a valid age" << endl;
                              i--;
                      }
              }
              average =ave(ParentsAge,sizeof(ParentsAge)/sizeof(double));
              cout << endl ;
                      cout << "Average age of Parents seeking Invetro is: "<< average << endl;   //output of averages
              return (0);
      }


Output:
1
2
3
cc1plus: warnings being treated as errors
In function 'double ave(double*, int)':
Line 11: warning: 'sum' may be used uninitialized in this function


Create a new paste based on this one


Comments: