LNK 2019 && Lnk1120

I have been looking around on the forums, and most people say this is called when a function does not have a body but I have checked and all have a body. I am not sure where to continue from here....
It is split between the header where the prototypes are located a separate .cpp file where it defines all the functions, and finally the main one.


Here is the .h file(account.h)
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
#pragma once
#include<string>
using namespace std;

class Account
{
private:
	int accountId;
	double balance;
	double annualInterestRate;

public:
	Account();
	Account(int id, double bal, double interest);

	void setAccountId(int x);
	// Function to set accountId based on passed parameter.
	// Postcondition: accountId = x;

	void setBalance(double x);
	// Function to set balance based on passed parameter.
	// Postcondition: balance = x;

	void setInterest(double x);
	// Function to set annualInterestRate based on passed parameter.
	// Postcondition: annualInterestRate = x;

	int getAccountId();
	// Function to set accountId.
	// Postcondition: accountId is returned.

	double getBalance();
	// Function to set balance.
	// Postcondition: balance is returned.

	double getInterest();
	// Function to set annualInterestRate.
	// Postcondition: annualInterestRate is returned.

	double getMonthlyInterestRate();
	// Function to calculate the monthly interest rate.
	// Postcondition: Monthly interest rate is calculated and returned.

	double getMonthlyInterest();
	// Function to calculate the amount that would be earned through monthly interest.
	// Postcondition: Amount that will be earned through monthly interest is calculated and returned.

	bool withdraw(double amount);
	// Function to reduce the account's current balance by the passed parameter, but only if the balance 
	// is greater than the passed in parameter.  If successful, return true, otherwise return false.
	// Postcondition: if (balance > amount) balance = balance - amount and return true;
	//				  otherwise return false;

	void deposit(double amount);
	// Function to increase the account's current balance by the passed parameter.
	// Postcondition: balance = balance + amount;
};

Last edited on
Here is the .ccp file (Account.cpp)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include"account.h"
#include<iostream>
using namespace std;

Account::Account()//Default Constructor
{
	accountId = 0;
	balance = rand() % 10000 + 10000;
	annualInterestRate=0;



}
void Account::setAccountId(int x)
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: setAccountID                                          
	//                                                                   
	// Description:
	//		Function to set accountId based on passed parameter.
	// 
	//
	// Parameters:  
	//    Postcondition: accountId = x;             
	//                                                       
	// Returns:  
	//    Void               
	//                                            
	///////////////////////////////////////////////////////////////////////
	*/
	
	//I am setting the account so maybe a Rand?
	accountId = x;

}
Account::Account(int id, double bal, double interest)
{
	accountId = id;
	balance = bal;
	annualInterestRate = interest;

}

void Account::setBalance(double x)
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: setBalance                                       
	//                                                                   
	// Description:
	//		Function to set balance based on passed parameers
	// 
	//
	// Parameters:  
	//     Postcondition: balance = x;           
	//                                                       
	// Returns:  
	//    Void               
	//                                            
	*///////////////////////////////////////////////////////////////////////
	balance = x;
}


void Account::setInterest(double x)
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: setBalance                                       
	//                                                                   
	// Description:
	//		Function to set annualInterestRate based on passed parameter.
	// 
	//
	// Parameters:  
	//     Postcondition: annualInterestRate = x;           
	//                                                       
	// Returns:  
	//    Void               
	//                                            
	*///////////////////////////////////////////////////////////////////////
	annualInterestRate = x;

}


int Account::getAccountId()
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: getAccountId                                 
	//                                                                   
	// Description:
	//		Function to set accountId.   
	// 
	//
	// Parameters:  
	//                
	//                                                       
	// Returns:  
	//   The account id(Integer)              
	//                                            
	*///////////////////////////////////////////////////////////////////////
	return accountId;
}


double Account::getBalance()
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: getBalnace                                
	//                                                                   
	// Description:
	//		function to set the Balnace  
	// 
	//
	// Parameters:  
	//                
	//                                                       
	// Returns:  
	//   The balance(Double)              
	//                                            
	*///////////////////////////////////////////////////////////////////////
	return balance;
}


double Account::getInterest()
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: getIntrest                              
	//                                                                   
	// Description:
	//		function to set the AnnalIntrestRate
	// 
	//
	// Parameters:  
	//                
	//                                                       
	// Returns:  
	//   The anual intrest Rate (Double)              
	//                                            
	*///////////////////////////////////////////////////////////////////////
	return annualInterestRate;

}


double Account::getMonthlyInterestRate()
{
	double y = 0.0;
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: getMonthlyInerestRates
	//
	// Description:
	//		function to calculate the monthly interest rate
	//
	//
	// Parameters:
	//
	//
	// Returns:
	//   Monthly inerest rate is calculuated and returned
	//
	*///////////////////////////////////////////////////////////////////////
	y = annualInterestRate / 12;
	return y;

}

double Account::getMonthlyInterest()
{
	double k;// this will get how much it has increase
	/*/////////////////////////////////////////////////////////////////////
	//
	// Function: getMonthlyInterest
	//
	// Description:
	//		function to calculate the amount that would be earned through monthly interest
	//
	//
	// Parameters:
	//
	//
	// Returns:
	//   The monthly inerest rates (Double)
	//
	*///////////////////////////////////////////////////////////////////////
	 k = balance*getMonthlyInterestRate();
	 k = k + balance;
	 return k;
}
bool Account::withdraw(double amount)
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: Withdraw                               
	//                                                                   
	// Description:
	//		Function to reduce the account's current balance by the passed parameter, but only if the balance 
	//			is greater than the passed in parameter.  If successful, return true, otherwise return false.
	//
	// Parameters:  
	//             Double amount   
	//                                                       
	// Returns:  
	//   True or false           
	//                                            
	*///////////////////////////////////////////////////////////////////////
	if (amount > balance)
	{
		return false;
	}
	else
	{
		balance = balance + amount;
		return true;
	}


}
// Postcondition: if (balance > amount) balance = balance - amount and return true;
//				  otherwise return false;

void Account::deposit(double amount)
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: deposit                               
	//                                                                   
	// Description:
	//		 Function to increase the account's current balance by the passed parameter.
	//
	// Parameters:  
	//             Double amount   
	//                                                       
	// Returns:  
	//          
	//                                            
	*///////////////////////////////////////////////////////////////////////
	balance = amount + balance;


}

Last edited on
and finally here is the main .cpp (AccountMain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include<iostream>
#include<string>
#include"account.h"
using namespace std;

int EnterAccountNumber();
void menuSelecton(int _accountId);


int main()
{	//Set variables up 
	
	int UsersId = -3;// Make sure it isn't a usable account

	UsersId=EnterAccountNumber();
	void menuSelection(int UsersId);
}

int EnterAccountNumber()
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: EnterAccountNumber
	//
	// Description:
	//		It will ask the user what is their account number and return
	//
	// Parameters:
	//   
	//
	// Returns:
	//    Their account number
	//
	///////////////////////////////////////////////////////////////////////
	*/
	int n = 0;
	cout << "Please enter an account number from 0 - 9 " << endl;
	cin >> n ;
	return n;
};
void menuSelecton(int _accountId)
{
	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: MenuSelection
	//
	// Description:
	//		Acts as the menu for the user to check their account balance monthy rates withdraw and deposit 
	//
	// Parameters:
	//		account ID which is will use it as the index for the accoutn array
	//
	// Returns:
	//		void
	//
	*///////////////////////////////////////////////////////////////////////
	Account accounts[10];
	accounts[_accountId];


	/*//////////////////////////////////////////////////////////////////////
	//
	// Function: menuSelection
	//
	// Description:
	//		This lets the user select their function for their spesific account
	//
	//
	// Parameters:
	//    
	//
	// Returns:
	//    Void
	//
	///////////////////////////////////////////////////////////////////////
	*/
	// You might need to add the account as a pass by 
	cout << "Enter 1 to make a deposit" << endl <<
			"Enter 2 to make a withdrawl" << endl <<
			"Enter 3 to check Balance" << endl <<
			"Enter 4 to check intrest rate" << endl <<
			"Enter 5 to display account summary" << endl<<
			"Enter -1 to return to the main menu:"<<endl;
	int Selection;
	double deposit = 0.0;
	double withdrawl = 0.0;
	cin >> Selection;
	switch (Selection)
	{
	case 1:
		//Function for deposit
		cout << "How much would you like to deposit ";
		cin >> deposit;
		accounts[_accountId].deposit(deposit);
		cout << endl << "Thank you a total of " << deposit << " has been depositied " << endl <<
			"Your total is now" << accounts[_accountId].getBalance() << endl;
		break;
	case 2: 
		// Function for withdrawl
		cout << "How much would you like to withdraw? ";
			cin >> withdrawl;
			if (accounts[_accountId].withdraw(withdrawl) == false)
			{
				cout << "Sorry you do not have enough please try again later";
			}
			else
			{
				cout << "You have withdrawn " << withdrawl << endl <<
						"You now have " << accounts[_accountId].getBalance() << endl <<
						"come again!" << endl;
			}

		break;
	case 3:
		//Function to check balance
		cout << "Your current balance is " << accounts[_accountId].getBalance()
			<< endl << "thank you have a great day!";
		break;
	case 4: 
		// Function to check the Monthly intrest rates and yearly
		cout << "Your Monthly intrest is " << accounts[_accountId].getInterest() << endl <<
			"Your yearly intrest is " << accounts[_accountId].getMonthlyInterestRate() << endl;
		break;
	case 5:
		// Check ID, Balance,, Monthly intrest rate and monthly amount
		cout << "Your account ID is " << accounts[_accountId].getAccountId() << endl <<
				"Your monthly intrest rate is " << accounts[_accountId].getMonthlyInterestRate() << endl <<
			"	your monthly intrest for this month is " << accounts[_accountId].getMonthlyInterest() << endl;
		break;
	case -1:
		
		break;
	default:
		//Add same program back into here
		cout << "Invalid Seleciton..." << endl << endl << endl;


	};


}

Last edited on
Just telling us a couple of error numbers isn't very helpful. Your linker will be giving you detailed information on which symbols it thinks are undefined, and which object files are trying to use those symbols. Why keep that information secret from us?

EDIT:

What is line 58 of your main cpp file supposed to be doing? Because it isn't doing anything.
Last edited on
line 58 is supposed to tell the program what index of the array to reference, as for the error

lnk2019 Unresolved external symbol _main refrenced in function "int _cdecl invoke_main (void)" (? invoke_main@@YAHXZ), file MSVCRTD.lib line 1


lnk1120 1 unresolved externals
line 58 is supposed to tell the program what index of the array to reference

How do you mean? Reference where?

That line does nothing. accounts[_accountId] is just a single object. It's the equivalent of having:

1
2
Account myAccount;
myAccount;


That link error is telling you that the linker can't find your main function. This is probably because you've made a mistake in setting up your project in Visual Studio.
Last edited on
I took out that line after I realized what you were saying. I found the issue to be in the other Cpp file that doesn't include the main.I re did the program, but still haven't found the issue.
I found the issue to be in the other Cpp file that doesn't include the main.

Can you elaborate on what you mean by that? How is something in your other file, causing the linker to be unable to find your main function?
I made another Project copy and pasted the .h file, no error, then the .cpp file that didn't have a main but just the definitions and that got me the error
So... you don't have a main function in your project, and when you try and build it, it fails because it can't find a main function.

Does it not strike you that there might be a more obvious reason for the error, than something being wrong with account.cpp?
I guess, though, with a main it still does not work...
In case anyone ever stumbles upon this. I had it for a win32 project and everything is set up correctly, My professor just let me do it in a blank project
Topic archived. No new replies allowed.