Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function minMaxAvg that calculates and returns the minimum, maximum, and average of three integers. Then write a main program to test your function.
Write a function minMaxAvg that calculates and returns the minimum, maximum, and average of three integers. Then write a main program to test your function.
Your main program should:
-
- ask the user to enter three integers,
-
- calls the function minMaxAvg to compute the minimum, maximum and average of the
three entered integer values,
-
- print the minimum, maximum, and average (minimum, maximum, average need to be
sent by reference).
Sample run:
Please enter 3 numbers: 100
The average is: 90.66
The min is: 80
The max is: 100
This is my code but im not getting the correct outputs when I test my code. Help All three parts of the outputs aren't matching (min,max,average). #include using namespace std; void minMaxAvg(int n1, int n2, int n3, int &min, int &max, double &avg) { min = n1; if(n2 < min) min = n2; if(n3 < min) min = n3; max = n1; if(n2 > max) max = n2; if(n3 > max) max = n3; avg = (n1 + n2 + n3) / 3.0; } int main() { int n1, n2, n3, min, max; double avg; cout << "Please enter 3 numbers: "; cin >> n1 >> n2 >> n3; minMaxAvg(n1, n2, n3, min, max, avg); cout << "The average is: " << avg << endl; cout << "The min is: " << min << endl; cout << "The max is: " << max << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started