Overloading Functions

I'm learning about overloading functions. The program must multiply an integer, double and a combination of integer and double.

What I'm having trouble with is where to put the operations and how to display them in each function. Below is my code and as you can see I have the basics.

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

int main()
{
	int a = 10;
	double b = 6.5;

	system("pause");
	return 0;
}

void multiply(int a)
{
	cout << "The product of the integer is: " << 
}

void multiply(double b)
{
	cout << "The product of the double is: " << 
}

void multiply(int a, double b)
{
	cout << "The product of the integer and the double is: " << 
}
Last edited on
If you declare main before your other functions, you still have to declare the function signature before main.

I'm not sure what you want to display. What does it mean to multiply one number? Should it just print itself out?

Here's a complete example using your code, just as demonstration of function overloading:
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
// Example program
#include <iostream>
#include <string>
using std::cout;

void multiply(int);
void multiply(double);
void multiply(int, double);

int main()
{
	int a = 10;
	double b = 6.5;

	multiply(a);
	multiply(b);
	multiply(a, b);
}

void multiply(int a)
{
	cout << "The product of the integer is: " << a << '\n';
}

void multiply(double b)
{
	cout << "The product of the double is: " << b << '\n';
}

void multiply(int a, double b)
{
	cout << "The product of the integer and the double is: " << a * b << '\n';
}
Last edited on
I think it's asking to display the product of the integer and double multiplied by itself. I figured out from your finished example though. Thanks for the help!
Topic archived. No new replies allowed.