Function max with 3 C++ arguments

• So, there's a task in which the max function has three arguments, but the standard max function has only two arguments, and it's true that in an attempt to introduce a third argument, it makes a mistake. `C2064 результатом вычисления фрагмента не является функция, принимающая 2 аргументов`

Source:

My decision is:

``````#include<iostream>
#include<algorithm>
using namespace std;
double max3(double a1, const double b1, const double c1)
{
return a1 > b1 ? a1 > c1 ? a1 : c1 : b1 > c1 ? b1 : c1; // max3 = max(a + b * c, 1., 15.)
}
double maximum(double a, double b, double c, double max3)
{
return (max(a, a + b) + max(a, b + c)) / (1 + max3);
}
int main()
{
double a, b, c;
const double b1 = 1.;
const double c1 = 15.;
cin >> a >> b >> c;
double a1 = a + b * c;
cout << "Answer: " << maximum(a, b, c,max3(a1, b1, c1));
}
``````

• Beginning `C++11``std::max` understand. `initializer_list` of any number of arguments that make it possible to rid itself of cycles

``````#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
double a = 33;
double b = -2;
const double c = 12;
cout << max({a,b,c}) << endl;
return 0;
}
``````

https://ideone.com/18Xmeh

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2