Function Overloading Problem

closed account (Diz60pDG)
I am writing a program where I am suppoosed to write three functions named get_input() that read a value from the user. One gets an int value from the user, the other gets a double value and the third gets a char value, and then a main() function to test all three.

Here is what I have so far, I am just confused as to what I put in the main function

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
#include <iostream>
using namespace std;

double get_input(int integer);
double get_input(double value);
double get_input(char character);


double get_input(int integer)
{
	cout << "Enter integer value: " ;
	cin >> integer;
	return integer;
}
double get_input(double value)
{
	cout << "Enter double value: ";
	cin >> value;
	return value;
}
double get_input(char character)
{
	cout << "Enter a character value: ";
	cin >> character;
	return character;
}

int main()
{
	
}
I assume that these functions should return value of the same type as their parameters (int in --> int out), but you always return double.

Test them:
1
2
3
cout << get_input(1) << endl
     << get_input(1.0) << endl
     << get_input('1') << endl;
Last edited on
Topic archived. No new replies allowed.