Overloaded functions

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
int getValue(int);
double getValue(double);


int main()
{
	int intnumber;
	double doublenumber;

	getValue(intnumber);
	getValue(doublenumber);

	cout << "Integer is : " << intnumber << endl;
	cout << "floating point is: " << doublenumber << endl;
	return 0;
}

int getValue(int inputValue)
{
	cout << "Enter an integer: ";
	cin >> inputValue;
	return inputValue;
}

double getValue(double inputValue)
{
	cout << "Enter a floating-point number: ";
	cin >> inputValue;
	return inputValue;
}


So Maybe im not understanding overloaded functions and their assigned variables to return. But shouldnt the return "inputvalue" define the variables intnumber and doublenumber?

thank you
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
// int getValue(int);
// double getValue(double);

int getValue( int& ); // passed by reference
double getValue( double& );


int main()
{
	int intnumber;
	double doublenumber;

	getValue(intnumber);
	getValue(doublenumber);

	cout << "Integer is : " << intnumber << endl;
	cout << "floating point is: " << doublenumber << endl;
	return 0;
}

// int getValue(int inputValue)
int getValue( int& inputValue )
{
	cout << "Enter an integer: ";
	cin >> inputValue;
	return inputValue;
}

// double getValue(double inputValue)
double getValue( double& inputValue )
{
	cout << "Enter a floating-point number: ";
	cin >> inputValue;
	return inputValue;
}
why though does it still return errors regarding the variables?
When experiencing errors, please post the exact text of the error messages.

Try including the following:
1
2
#include <iostream>
using namespace std;

Oh i just omitted those. apprently it does work, i dont know why but sometimes my projects return errors until i put them into a new source file and rerun.. anyone ever experience this?
Topic archived. No new replies allowed.