[try Beta version]
Not logged in

 
Problem with Multiple "mains"

Dec 20, 2008 at 3:32am
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_
Dec 20, 2008 at 3:51am
i think you need to declare the other functions before main()

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

int main()
{
//....
}
Dec 20, 2008 at 4:33am
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.
Dec 20, 2008 at 6:20am
He thinks that they are other mains. To be clear, you can only have ONE main, a.k.a main();.
Dec 20, 2008 at 10:27pm
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
Dec 20, 2008 at 11:02pm
You could make the other "mains" functions, maybe?
Dec 21, 2008 at 3:12am
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 Dec 21, 2008 at 3:16am
Topic archived. No new replies allowed.