Overloading functions on c++

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.

My code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

using namespace 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;
	else 
		return a;
}
int sumNumber(int a, int b, int c)
{
	if(a < b && b < c)
		return a;
	else if (b < a && a < c)
		return b;
	else if (c < b && b < a)
		return c;
}
This is as efficient as you will need it, Btw though - Test if all 3 numbers are the same
Topic archived. No new replies allowed.