Hello, does this code seem avoid a duplication of code in each of these functions? I need to call one function from within another and that's it. I also have to use the two argument version of the function inside the three argument version function.
#include <iostream>
usingnamespace std;
int sumNumber(int a, int b);
int sumNumber(int a, int b, int c);
int main()
{
int x, y, z;
cout << "Enter three whole numbers." << endl;
cin >> x;
cin >> y;
cin >> z;
cout << "The smallest of the first two numbers is " << sumNumber(x, y) << "." << endl;
cout << "The smallest of all three numbers is " << sumNumber(x, y, z) << "." << endl;
return 0;
}
int sumNumber(int a, int b)
{
if(b < a)
return b;
elsereturn a;
}
int sumNumber(int a, int b, int c)
{
if(a < b && b < c)
return a;
elseif (b < a && a < c)
return b;
elseif (c < b && b < a)
return c;
}