Functions overload

This is my code and it is not working properly so can any one help me in figuring out what is wrong. Thank you.

#include <iostream>

using namespace std;
int Average(long int input1, long int input2);
int Average(long int input1, long int input2, long int input3);
int Average(double input1, double input2);

int main()
{
long int input1, input2, input3;
double newinput1, newinput2;

cout << "Enter 3 integers" << endl;
cin >> input1 >> input2 >> input3;
cout << "The average of " << input1 << " and "<< input2 << " is " << Average(input1, input2)<< endl;
cout << "The average of " << input1 << " , " << input2 << " and " << input3 << " is " << Average(input1, input2, input3) << endl;
cout << "Enter 2 real numbers" << endl;
cin >> newinput1 >> newinput2;
cout << "The average of " << newinput1 << " and " << newinput2 << " is " << Average(newinput1, newinput2) << endl;


return 0;

}
int Average(long int input1, long int input2)
{
long int Avg = (input1 + input2) / 2;


return Avg;
}
int Average(long int input1, long int input2, long int input3)
{
long int Avg2 = (input1 + input2 + input3) / 3;

return Avg2;
}
int Average(double input1, double input2)
{
double Avg3 = (input1 + input2) / 2.0;


return Avg3;
}
This is my code and it is not working properly so can any one help me in figuring out what is wrong. Thank you.

Before that, can you tell us what problem you are encountering?
In my last function in which there are double arguments the out put should be 1.5 if the input is 1 and 2 because that is the average but it is not doing that.. It is just outputting 1 as the out put if I input 1 and 2
int Average(double input1, double input2);

Should be :
double AverageDouble(double input1, double input2);

And :
1
2
3
4
5
int Average(double input1, double input2)
{
    double Avg3 = (input1 + input2) / 2.0;
    return Avg3;
} 


Should be :
1
2
3
4
5
double AverageDouble(double input1, double input2)
{
    double Avg3 = (input1 + input2) / 2.0;
    return Avg3;
} 
Thank you very much.. That helped alot!!
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
39
40
41
42
43
44
45
46
#include <iostream>

using namespace std;
int Average(long int input1, long int input2);
int Average(long int input1, long int input2, long int input3);
double Average(double input1, double input2);

int main()
{
long int input1, input2, input3;
double newinput1, newinput2;

cout << "Enter 3 integers" << endl;
cin >> input1 >> input2 >> input3;
cout << "The average of " << input1 << " and "<< input2 << " is ";
cout << Average(static_cast<long int>(input1), static_cast<long int>(input2)) << endl;

cout << "The average of " << input1 << " , " << input2 << " and " << input3 << " is ";
cout << Average(input1, input2, input3) << endl;

cout << "Enter 2 real numbers" << endl;
cin >> newinput1 >> newinput2;
cout << "The average of " << newinput1 << " and " << newinput2 << " is ";
cout << Average(static_cast<double>(newinput1), static_cast<double>(newinput2)) << endl;


return 0;

}
int Average(long int input1, long int input2)
{
    long int Avg = (input1 + input2) / 2;
    return Avg;
}

int Average(long int input1, long int input2, long int input3)
{
    long int Avg2 = (input1 + input2 + input3) / 3;
    return Avg2;
}

double Average(double input1, double input2)
{
    double Avg3 = (input1 + input2) / 2.0;
    return Avg3;
} 
Last edited on
Topic archived. No new replies allowed.