Function

Hi. I am new to C++ and i tried to break a main file to 3 parts and i got these 2 error which i don't know wat it is

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\Zx\Desktop\Notes\Computing\assg5q1\Debug\assg5q1.exe : fatal error LNK1120: 1 unresolved externals



Do you mind posting the code?
you dont have a main() function defined in any of your .cpp files.
menufunction.h.h

# include <iostream>
# include <cstdlib>
using namespace std ;

extern int choice ;
int switchstatement (int) ;

main.cpp

# include "menufunction.h.h"
int choice ;
void CoinExchange(float &fifty , float &twenty , float &ten , float &five , float &one) ;
void casestatement() ;
void LYD () ;
char menuinput(void)
{
cout <<"\n-------------------------------------------\n"
<<"\n 1. [C}oin Exchange \n"
<<"\n 2. [L]eap Year Determination \n"
<<"\n 3. [P]ostage Calculation \n"
<<"\n 4. Prime [N]umber Generator \n"
<<"\n 5. [Q]uit \n"
<<"\n-------------------------------------------\n"
<<"Your Choice is : " ;
cin >> choice ;
void casestatement() ; void LYD () ;
cout <<endl ;

system("pause") ;
return 0 ;
}

menufunction.cpp.cc

# include "menufunction.h.h"

void casestatement()
{
switch (choice)
{
case 1 :
void CoinExchange(float fifty , float twenty , float ten , float five , float one) ;
break ;
case 2 :
void LYD () ;
break ;
}
}

void CoinExchange(float &fifty , float &twenty , float &ten , float &five , float &one)
{
float Money ;
cout << "Please key in the total amount change (cents) " ;
cin >> Money ;
cout << endl ;
fifty = Money/50 ;
twenty = (Money - fifty*50)/20 ;
ten = (Money - twenty*20-fifty*50)/10 ;
five = (Money - twenty*20-fifty*50-ten*10)/5 ;
one = (Money - twenty*20-fifty*50-ten*10-five*5) ;
cout << fifty ;
cout << twenty ;
cout << ten ;
cout << five ;
cout << one ;
}

void LYD ()
{
int year ;
cout << "Please key in a year " ;
cin >> year ;
if (year % 4 != 0)
{
cout << year
<< "is not a leap year" ;

if (year % 400 == 0 )
cout << year
<< " is a leap year " ;

else if ( year % 100 != 0)
cout << year
<< " is a leap year " ;
else
cout << year
<< " is not a leap year " ;
}

cout << endl ;
}

I am only half way through the program but first i need to fix this 2 error. Thank you

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\Zx\Desktop\Notes\Computing\assg5q1\Debug\assg5q1.exe : fatal error LNK1120: 1 unresolved externals


Last edited on
For the beneft of other users...

1
2
3
4
5
6
7
8
menufunction.h.h

# include <iostream>
# include <cstdlib>
using namespace std ;

extern int choice ;
int switchstatement (int) ;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
main.cpp

# include "menufunction.h.h"
int choice ;
void CoinExchange(float &fifty , float &twenty , float &ten , float &five , float &one) ;
void casestatement() ;
void LYD () ;
char menuinput(void)
{
cout <<"\n-------------------------------------------\n"
<<"\n 1. [C}oin Exchange \n" 
<<"\n 2. [L]eap Year Determination \n"
<<"\n 3. [P]ostage Calculation \n"
<<"\n 4. Prime [N]umber Generator \n"
<<"\n 5. [Q]uit \n" 
<<"\n-------------------------------------------\n"
<<"Your Choice is : " ;
cin >> choice ;
void casestatement() ; void LYD () ;
cout <<endl ;

system("pause") ;
return 0 ;
}


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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
menufunction.cpp.cc

# include "menufunction.h.h"

void casestatement()
{
switch (choice)
{
case 1 :
void CoinExchange(float fifty , float twenty , float ten , float five , float one) ;
break ; 
case 2 :
void LYD () ;
break ;
}
}

void CoinExchange(float &fifty , float &twenty , float &ten , float &five , float &one) 
{
float Money ;
cout << "Please key in the total amount change (cents) " ;
cin >> Money ; 
cout << endl ;
fifty = Money/50 ;
twenty = (Money - fifty*50)/20 ;
ten = (Money - twenty*20-fifty*50)/10 ;
five = (Money - twenty*20-fifty*50-ten*10)/5 ;
one = (Money - twenty*20-fifty*50-ten*10-five*5) ;
cout << fifty ;
cout << twenty ;
cout << ten ;
cout << five ;
cout << one ;
}

void LYD ()
{
int year ;
cout << "Please key in a year " ;
cin >> year ;
if (year % 4 != 0)
{
cout << year 
<< "is not a leap year" ;

if (year % 400 == 0 )
cout << year 
<< " is a leap year " ;

else if ( year % 100 != 0)
cout << year
<< " is a leap year " ;
else 
cout << year 
<< " is not a leap year " ;
}

cout << endl ;
}
where is the main() function defined?? thats the error,linker is not able to find main().
OIC LOL I realise where is the problem thank you.
Last edited on
Topic archived. No new replies allowed.