I AM GETTING "error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup" and another error of "error LNK1120: 1 unresolved externals" WHEN I RUN THE PROJECT BELOW. WHAT DO I NEED TO CHANGE TO FIX THE ERRORS.
header_file.h:
#include #include #include
using std::cin; using std::cout; using std::endl; using std::vector; using std::string;
typedef struct Account{ int accountNumber; string lastName; string firstName; double accountBalance; }Account;
void menu(); template void makeAccount(vector &); template void printAllAccounts(vector ); template void printAccount(vector ); template void depositAccount(vector &); template void withdrawAccount(vector &); template void deleteAccount(vector &); template void sortAccounts(vector &);
-----------------------------------------------------------------------------------------------------
function.cpp:
#include "header_file.h" #include #include #include #include #include
using std::cin; using std::cout; using std::endl; using std::vector; using std::string;
void menu(int *num) { int choice = 0; cout << "Welcome to MadeUp Banking. Select options below:" << endl; cout <<" 1. Make new account." << endl; cout <<" 2. Display all accounts." << endl; cout <<" 3. Deposit to an account." << endl; cout <<" 4. Withdraw from an account." << endl; cout <<" 5. Print account." << endl; cout <<" 6. Delete an account." << endl; cout <<" 7. Quit." << endl; cout <<" Selection: "; cin >> choice; while(choice < 1 || choice > 7) { cout << "Invalid choice. Enter a valid choice: "; cin >> choice; } *num = choice; } template void makeAccount(vector & myVec) { bool duplicate = true; int accNum; string fName, lName; double balance; while(duplicate) { duplicate = false; accNum = rand() % 9000 + 1000; for(int i = 0; i < myVec.size(); i++) if(myVec[i].accountNumber == accNum) duplicate = true; if(!duplicate) break; } cout << "Creating bank account number " << accNum << endl; typeStruct account; account.accountNumber = accNum; cout << "Enter first name: "; cin >> fName; account.firstName = fName; cout << "Enter last name: "; cin >> lName; account.lastName = lName; cout << "Enter starting balance: "; cin >> balance; account.accountBalance = balance; myVec.push_back(account); } template void printAllAccounts(vector myVec) { for(int i = 0; i < myVec.size(); i++) { cout << "Account number: " << myVec[i].accountNumber << "\t"; cout << "Balance: " << fixed << setprecision(2) << myVec[i].accountBalance << endl; cout << "Last name: " << myVec[i].lastName << "\t" << "First name: " << myVec[i].firstName << endl; } } template void printAccount(vector myVec) { int accNum; cout << "Enter the account number: "; cin >> accNum; bool found = false; for(int i = 0; i < myVec.size(); i++) { if(myVec[i].accountNumber == accNum) { cout << "Account number: " << myVec[i].accountNumber << "\t"; cout << "Balance: " << fixed << setprecision(2) << myVec[i].accountBalance << endl; cout << "Last name: " << myVec[i].lastName << "\t" << "First name: " << myVec[i].firstName << endl; found = true; break; } } if(!found) cout << "Account number doesn't exist..." << endl; } template void depositAccount(vector &myVec) { int accNum; double amount; cout << "Enter the account number to deposit: "; cin >> accNum; cout << "Enter amount to be deposited: "; cin >> amount; bool found = false; for(int i = 0; i < myVec.size(); i++) { if(myVec[i].accountNumber == accNum) { myVec[i].accountBalance += amount; found = true; break; } } if(!found) cout << "Account number doesn't exist..." << endl; } template void withdrawAccount(vector & myVec) { int accNum; double amount; cout << "Enter the account number to withdraw: "; cin >> accNum; cout << "Enter amount to be withdrawn: "; cin >> amount; bool found = false; for(int i = 0; i < myVec.size(); i++) { if(myVec[i].accountNumber == accNum) { myVec[i].accountBalance -= amount; found = true; break; } } if(!found) cout << "Account number doesn't exist..." << endl; } template void deleteAccount(vector & myVec) { int accNum; double amount; cout << "Enter the account number to delete: "; cin >> accNum; bool found = false; for(int i = 0; i < myVec.size(); i++) { if(myVec[i].accountNumber == accNum) { myVec.erase(myVec.begin() + i); found = true; break; } } if(!found) cout << "Account number doesn't exist..." << endl; } template void sortAccounts(vector & bankAccounts) { for(int i = 0; i < bankAccounts.size()-1; i++) for(int j = 0; j < bankAccounts.size()-i-1; j++) if(bankAccounts[j].accountNumber > bankAccounts[j+1].accountNumber) { typeStruct temp = bankAccounts[j]; bankAccounts[j] = bankAccounts[j+1]; bankAccounts[j+1] = temp; } }
----------------------------------------------------------------------------------------------------------
main.cpp:
#include "function.cpp" #include "header_file.h" #include #include #include #include #include
using std::cin; using std::cout; using std::endl; using std::vector; using std::string;
int main() { vector accounts; while(true) { int choice = menu(); switch(choice) { case 1: makeAccount(accounts); break; case 2: printAllAccounts(accounts); break; case 3: depositAccount(accounts); break; case 4: withdrawAccount(accounts); break; case 5: printAccount(accounts); break; case 6: deleteAccount(accounts); break; case 7: return 0; default: cout << "Invalid menu..." << endl; } } }