i wrote this program that finds the smallest of three int numbers
but im confused on what the second part of the question is asking,
basically i have to modify my minValue function to send its output through a
reference parameter.
im guessing its something like this but im not exactly sure
1 2
void minValue(int& first, int& second, int& third);// function prototype
minValue(first, second, third) // function call
#include <iostream>
usingnamespace std;
int minValue(int first, int second, int third);// function prototype
int main()
{
int one, two, three;
int min;
cout << "Input three integer values. Press return." << endl;
cin >> one >> two >> three;
min = minValue(one, two, three); // function call
cout << "The minimum value of the three numbers is " << min << endl;
system("pause");
return 0;
}
int minValue(int first, int second, int third)// function definition with
{
if (first <= second && first < third)
{
return first;
}
elseif (second <= first && second < third)
{
return second;
}
else
{
return third;
}
}
Hey,
yeah thats the correct way to pass by reference.
I don't understand why you would want to pass byref though because no values are changed and the function already works as it is ?