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!!
#include <iostream>
#include <cstdlib>
#include <iomanip>
usingnamespace 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;
}
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.