Need help printing max value using functions

Hi, i need help with an assignment making this program to calculate the min, max, and avg values of user input, all equations should be done through functions and the results in main, however i am not receiving the correct results, please help!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cstdlib>
#include <iomanip>

using namespace std;

int max(int arraysize[], int actualsize);
int min(int arraysize[], int actualsize);
int average(int arraysize[], int actualsize);

int main()
{
    int maximum[1000]; int grades; int minimum[1000]; int grade[1000]; int avg[1000];
    cout << "enter how many grades you would like to calculate: ";
    cin>>grades;
    for(int i=0;i<=grades-1;i++){
        cout<<"enter grade: ";
        cin>>grade[i];
    }
    cout<<max(maximum, grades)<<endl;
    cout<<min(minimum, grades)<<endl;
    cout<<average(avg, grades)<<endl;


    return 0;
}


int max(int arraysize[], int actualsize)
{
    int highest; int i;
    for(i=0;i<=actualsize;i++) {
        if(arraysize[i]>highest)
        arraysize[i]=highest;
    }
    return highest;

}

int min(int arraysize[], int actualsize)
{

    int lowest=1000000000; int i;
    for(i=0;i<=actualsize;i++)
    {
        if(arraysize[i]<lowest)
            lowest=arraysize[i];
    }
    return lowest;
}

int average(int arraysize[], int actualsize)
{
    int average=0; int i;
    for(i=0;i<=actualsize;i++)
    {
        average+=arraysize[i];
    }


    return average;
}
Last edited on
Look at the following snippet:
1
2
3
        cin>>grade[i];
    }
    cout<<max(maximum, grades)<<endl;


Where do you ever assign any values to your maximum[] array? Wouldn't it be better to pass the grade[] array?

how would i pass the grade exactly? and it's not just the max, im receiving incorrect values for both the average and minimum functions as well, although i feel that snippet is the issue however im not really sure how to go about fixing it
Why are you trying to pass the maximum array to the function when you have never filled in that array? Why do you even need that array? (You don't.)

how would i pass the grade exactly?

How are you passing maximum?

and it's not just the max, im receiving incorrect values for both the average and minimum functions as well,

Yes, that's because your doing the same basic thing wrong with all the functions. The grade[] array has the data you need to pass this array, not those empty unneeded arrays.

Topic archived. No new replies allowed.