find average of 10 numbers passed to an array using function. the array should be con

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sabi
    New Member
    • Jun 2012
    • 1

    find average of 10 numbers passed to an array using function. the array should be con

    find the average of 10 numbers to an array using function .the array should be controlled by while loop?

    Code:
    #include <iostream.h>
    float sum(float x[],int size);
        main()
    {
       float a[10];
    int n=10;
    while (n<10)
    
    {
       cin>>a[n];
    n++;
    }
    cout<<"avg = "sum (a+n)/n;
    }
    floatsum(floatx{},int size)
    {
    float total=o;
    for(int i=0,i<size,i++);
    {
    total=total +x[i];
    }
    return total;
    }
    Last edited by Niheel; Jun 21 '12, 03:53 PM. Reason: include code with your question
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What is your question exactly?

    Please post your code after it compiles.

    It looks like you are on the right track.

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      The include file is <iostream>
      main() should return an int e.g. int main()
      The prototype sum() function is different to the sum ()function definition.
      total is initialized with 'o' not '0'
      Your while loop can't loop as n is assigned 10 when the loop condition is n<10.
      The float x[] should not have {} brackets
      By surrounding your code with code tags others can more easily read it.

      Comment

      Working...