I need a way to return the maximum value of five numbers
This is the explanation
•function -- identify the maximum value of the five integers
◦function name: maxValue
◦function parameters: five integers, pass-by-value
◦function return: the maximum value of the five integers, as an integer
This is what I have, but i think it is wrong. Also, what should I write in main.
int maxValue (int n1, int n2, int n3, int n4, int n5);
int main()
{
cout << "Enter in 5 numberss (between 1 and 100):\n";
cin >> n1;
cin >> n2;
cin >> n3;
cin >> n4;
cin >> n5;
return 0;
}
int maxValue (int n1, int n2, int n3, int n4, int n5)
{
int max;
if ((n1 >= n2) && (n1 >= n3) && (n1 >= n4) && (n1 >= n5))
{
max = n1;
}
else if ((n2 >= n1) && (n2 >= n3) && (n2 >= n4) && (n2 >= n5))
{
max = n2;
}
else if ((n3 >= n1) && (n3 >= n2) && (n3 >= n4) && (n3 >= n5))
{
max = n3;
}
else if ((n4 >= n1) && (n4 >= n2) && (n4 >= n3) && (n4 >= n5))
{
max = n4;
}
else if ((n5 >= n1) && (n5 >= n2) && (n5 >= n3) && (n5 >= n4))
{
max = n5;
}
return max;
}