function help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thebrainmore
    New Member
    • Oct 2006
    • 5

    function help

    could someone help with my average and sort functions in this program



    [code]#include <iostream.h>


    //funtion prototypes
    int FindLowNum(int [], int );
    int FindHighNum(int [], int);
    int average(int[] , int , double );
    void sorting(int [], int);

    //main function
    void main()
    {

    int A[10];
    int i;
    double avg;

    cout << "Enter Numbers Please:\n";

    for (int i=0;i<10;i++)
    {
    cin>>A[i];
    }


    for (i=0;i<10;i++)
    cout<< A[i]<<' '<<endl;


    cout << "the lowest value is :"<<FindLowNum( A, i)<<endl;

    cout << "the highest value is :"<<FindHighNum (A, i);

    cout << "the average value is :"<<average (avg);


    cout<< A[i]<<' '<< sorting (A, size);

    }


    //function to find the lowest number
    int FindLowNum(int array[], int size)
    {
    int lowest_so_far = array[0];
    for (int i=1; i<size; i++)
    {
    if (array[i]<lowest_so_fa r)
    lowest_so_far = array[i];
    }
    return lowest_so_far;

    }

    //funtion to find the highest number
    int FindHighNum(int array[], int size)
    {
    int highest_so_far = array[0];
    for (int i=1; i<size; i++)
    {
    if (array[i]>highest_so_far )
    highest_so_far = array[i];
    }
    return highest_so_far;

    }

    //function to return the average
    int average(int num[], int size, double avg)
    {
    for(int i=0; i<size; i++)
    {
    avg = (avg + num[i]);
    }
    avg = avg / size;


    return avg;
    }


    //function to sort numbers
    void sorting(int num[], int size)


    int higher=0;
    int highest=0;


    for(i = 1; i <= size, i++)
    {


    if(num[] > highest)
    highest = num[];
    else if (num[] >= higher && num[] < highest)
    higher = num;

    size += 1;
    }
    [code]
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What is the third parameter for in the average function? The function should be something like this
    Code:
    int average(int num[], int size) {
           int sum = 0; 
           for(int i=0; i<size; i++) {
               sum = sum + num[i];
            }
           avg = sum / (double)size;
           return avg;
    }
    your sort function is a mess. You need to look at a sorting tutorial

    Comment

    Working...