C++ functions help

ive been at this for two days cant seem to figure what i am doing wrong, maybe someone can help me and tell me what i am doing wrong.
the area where it gives me error are in the main function. it saystest1 test2 test3 minimum and maximum variable is being used without being initialized

//Ezaz Choudhry.
//project 1 funtions.

#include <iostream>

using namespace std;

void getscores(int & test1 , int & test2, int & test3);
double calcaverage(int test1, int test2, int test3);
void calcminmax(int test1,int test2,int test3,int minimum, int maximum);
void display(int test1, int test2, int test3, double average, int minimum, int maximum);
int main()
{
int test1, test2, test3, minimum, maximum;
double average;

// these next three lines is where it gives me error
average = calcaverage(test1,test2,test3);
calcaverage(test1,test2,test3);

display( test1, test2, test3, average, minimum, maximum);





system("pause");
return 0;
}
// asks the user for three test scores
void getscores(int & test1, int & test2, int & test3)
{
cout << "Enter the first test score : ";
cin >> test1;
cout << "Enter the second test score : ";
cin >> test2;
cout << "Enter the third test score : ";
cin >> test3;

}
// averages out the three test scores
double calcaverage(int test1, int test2, int test3)
{
return(test1 + test2 + test3) / 3.0;
}
// calculates the min and max
void calcminmax(int test1,int test2,int test3,int minimum,int maximum)
{
if (test1 <= test2 && test1 <= test3)
minimum = test1;
else if (test2 <= test1 && test2 <= test3)
minimum = test2;
else
minimum = test3;

if (test1 >= test2 && test1 >= test3)
maximum = test1;
else if (test2 >= test1 && test2 >= test3)
maximum = test2;
else
maximum = test3;
}

void display(int test1, int test2, int test3, double average, int minimum, int maximum)
{
cout << endl << "Results ..." << endl;
cout << "The test scores are " << test1 << " and " << test2 << " and "
<< test3 << endl;
cout << "The average of the test scores is " << average << endl;
cout << "The minimum test score is " << minimum << endl
<< "The maximum test score is " << maximum << endl;
}
Last edited on
You never call the getscores function to actually get the input, or the calcminmax to get the min and max. Call the getscore function before anything else. Also, in your calcminmax function, you need to pass minimum and maximum as references (like in your getscores function) or the actual variables won't be changed.
freddy92 thanks your the best, it worked.
Topic archived. No new replies allowed.