How to link two main() files ?

How to link these two main() files


lets say we have 2 main functions :

and let them be these

1.

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 sum(int a,int b)
{
	return (a+b);
}

int main()
{
	
	cout<<"\nEnter two numbers to add : ";
	int x,y;
	cin>>x>>y;
	if(!sum(x,y))
	{
		cout<<"\nNot able to Process\nOR\nSum is = 0";
	}
	else
	{
		cout<<"\nSum is : "<<sum(x,y);
	}

}


2.

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
#include<iostream>

using namespace std;

int sub(int a,int b)
{
	return (a-b);
}

int main()
{

	cout<<"\nEnter two numbers to subtract :(1st greater than second) ";
	int x,y;
	cin>>x>>y;
	if(!sub(x,y))
	{
		cout<<"\nNot able to Process";
	}
	else
	{
		cout<<"\nDifference is : "<<sub(x,y);
	}

}


How can you connect these using another main function

or

how can you include two main functions into another main function ??

------------->(in two other exe files)<----------------
Last edited on
A program can have only one main function. You can rename those functions and use them from some other new main.
> (in two other exe files)

Build the two executable images (say a.exe and b.exe) as usual.

From the third program, invoke these via a call to std::system()
http://en.cppreference.com/w/cpp/utility/program/system
Thank you very much JLBorges !!!

I got what you intended to mean.
Topic archived. No new replies allowed.