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;
}
``````

you haven't declared n1 to n5 as a variable at main, next create or use a previous variable that would accept the value returned by the maxValue function

I forgot to but the declaration here. my problem is how to make return.

in your main function call the maxvalue function and store the return value in a variable.

example: int result = maxvalue(v1, v2, v3, v4, v5);

Ok I did that
what I should write beside return ?

``````int main()
{
int n1 = 0,n2 = 0,n3 = 0,n4 = 0,n5 = 0, n6 = 100, max;

cout << "Enter in 5 numberss (between 1 and 100):\n";
cin >> n1;
cin >> n2;
cin >> n3;
cin >> n4;
cin >> n5;

max = maxValue (n1, n2, n3, n4, n5);

return 0;
}
``````

what I should write beside return ?

Use cout to inform you what max is.
Pause execution before `return 0;` so that you can see the result.

After that, look at ways to optimize your maxValue function.

My way is most simple. Using array. When you input number. Store it in to the array. And then find the max.