Problem with Multiple "mains"

I have been stumped by this problem, and its starting to get annyoing... Recently I asked my friend how can I have multiple sections on a Program.. So I gave it a try, I made two functions (I think you call it) Ones called
 
int secondmain()

thirdmain()


Note:Using Dev C++
So say I have a simple program,

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
#include <iostream>
using namespace std;
main()
{
 int secondmain();
 int thirdmain();

  // efjeifjeie

system("PAUSE");
return 0;
}

secondmain()

{

// Code exists, but will not run this section

system("PAUSE");
return 0;
}

thirdmain()

{

// Code exists, but will not run this section

system("PAUSE");
return 0;
}





But all it does is run the first main... So any comments or help? Thanks_
i think you need to declare the other functions before main()

1
2
3
4
5
6
7
int secondmain();
int thirdmain();

int main()
{
//....
}
Actually, the functions are being declared on lines 5 and 6. It's just that a) the function definitions don't have return types, and b) the functions themselves are never called.
He thinks that they are other mains. To be clear, you can only have ONE main, a.k.a main();.
He thinks that they are other mains. To be clear, you can only have ONE main, a.k.a main();.
|




Hince the quotations around "main" hint hint, I know you can only have one main
You could make the other "mains" functions, maybe?
This will work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

void secondmain();
void thirdmain();

int main() {
	secondmain();
	thirdmain();
	system("PAUSE");
	return 0;
}

void secondmain() {
	// Code exists, but will not run this section
	system("PAUSE");
}

void thirdmain() {
	// Code exists, but will not run this section
	system("PAUSE");
}
Last edited on
Topic archived. No new replies allowed.