mercredi 27 octobre 2021

C++ LNK2019 Unresolved External Symbol: What about my code is causing this error? [closed]

I am new to C++ and am having a hard time figuring this one out. I get the following two errors: LNK2019 "unresolved external symbol void_cdecl editExistingEntry(struct CustomerAccount * const, int) (? editExistingEntry@@YAXQUACustomerAccount@@H@Z) referenced in function_main

Followed by a LNK1120 error... My code will not even compile.

Here is my code:

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

struct CustomerAccount {
    string name;
    string address;
    string city;
    string state;
    string zip;
    string telephone;
    double acc_balance;
    string dateOfLastPayment;
};

// function prototyes
// enter new data function
void addNewEntries(CustomerAccount[], int);
// change existing data function
void editExistingEntry(CustomerAccount[], int);
// display data function
void displayEntries(const CustomerAccount[], int);

// main function
int main() {

    // variable to hold menu choice
    char choice;
    // named constant for number of customers
    const int NUM_CUSTOMERS = 10;
    // array to hold 10 CustomerAccount structures
    CustomerAccount customers[NUM_CUSTOMERS];

    // display menu
    cout << "Please choose an option from the following menu: \n";
    cout << "A) Enter new customers' data \n";
    cout << "B) Edit an existing customer's data \n";
    cout << "C) Display all customer data \n";
    cin >> choice;

    if (choice == 'a' || choice == 'A') {
        // call addNewEntries function
        addNewEntries(customers, NUM_CUSTOMERS);
    }

    if (choice == 'b' || choice == 'B') {
        // call editExistingEntry function
        editExistingEntry(customers, NUM_CUSTOMERS);
    }

    if (choice == 'c' || choice == 'C') {
        // call displayEntries function
        displayEntries(customers, NUM_CUSTOMERS);
    }
    return 0;
}

//****************************************************************************************************************
// displayEntries function: accepts array of customerAccount structures and its size as arguments, displays the 
// contents of the array.
//****************************************************************************************************************
void displayEntries(const CustomerAccount customers_array[], int size_of_array) {
    for (int index = 0; index < size_of_array; index++) {
        cout << "Customer #" << (index + 1) << endl;
        cout << "Name: " << customers_array[index].name << endl;
        cout << "Address: " << customers_array[index].address << endl;
        cout << "City: " << customers_array[index].city << endl;
        cout << "State: " << customers_array[index].state << endl;
        cout << "Zip: " << customers_array[index].zip << endl;
        cout << "Telephone: " << customers_array[index].telephone << endl;
        cout << "Account Balance: " << customers_array[index].acc_balance << endl;
        cout << "Date of Last Payment: " << customers_array[index].dateOfLastPayment << endl << endl;
    }
}

//****************************************************************************************************************
// addNewEntries function: accepts array of customerAccount structures and its size as arguments, allows the 
// user to enter data for 10 new customer accounts.
//****************************************************************************************************************
void addNewEntries(CustomerAccount customers_array[], int size_of_array) {
    // variable to temporarily hold account balance for input validation
    double temp_acc_balance;
    cout << "Enter the data for 10 customer accounts: ";
    for (int index = 0; index < size_of_array; index++) {
        cout << "Customer #" << (index + 1) << endl;
        // get name
        cout << "Enter Name: " << endl;
        getline(cin, customers_array[index].name);
        // get address
        cout << "Enter Address: " << endl;
        getline(cin, customers_array[index].address);
        // get city
        cout << "Enter City: " << endl;
        getline(cin, customers_array[index].city);
        // get state
        cout << "Enter State: " << endl;
        getline(cin, customers_array[index].state);
        // get zip
        cout << "Enter Zip: " << endl;
        getline(cin, customers_array[index].zip);
        // get telephone
        cout << "Enter Telephone: " << endl;
        getline(cin, customers_array[index].telephone);
        // get account balance
        cout << "Enter Account Balance: " << endl;
        cin >> temp_acc_balance;
        // validate input for account balance
        if (temp_acc_balance < 0) {
            cout << "You entered an invalid entry. Please run the program again and enter a positive value.\n";
        }
        else {
            customers_array[index].acc_balance = temp_acc_balance;
        }
        // get date of last payment
        cout << "Enter Date of Last Payment: " << endl;
        cin >> customers_array[index].dateOfLastPayment;
    }
}

//****************************************************************************************************************
// editExistingEntries function: accepts array of customerAccount structures as an argument, allows the 
// user to edit data for one of the 10 existing customer accounts.
//****************************************************************************************************************
void editExistingEntries(CustomerAccount customers_array[], int size_of_array) {
    // variable to hold user's choice 
    short customer_to_edit;
    // ask user which of the 10 accounts they want to edit
    cout << "Which of the 10 existing accounts would you like to edit? (Enter a value 1-10) \n";
    cin >> customer_to_edit;
    // allow user to edit the name of the chosen customer
    cout << "Edit Name: \n";
    cin >> customers_array[customer_to_edit - 1].name;
    // edit address
    cout << "Edit Address: \n";
    cin >> customers_array[customer_to_edit - 1].address;
    // edit city
    cout << "Edit City: \n";
    cin >> customers_array[customer_to_edit - 1].city;
    // edit state
    cout << "Edit State: \n";
    cin >> customers_array[customer_to_edit - 1].state;
    // edit zip
    cout << "Edit Zip: \n";
    cin >> customers_array[customer_to_edit - 1].zip;
    // edit telephone
    cout << "Edit Telephone: \n";
    cin >> customers_array[customer_to_edit - 1].telephone;
    // edit account balance
    cout << "Edit Account Balance: \n";
    cin >> customers_array[customer_to_edit - 1].acc_balance;
    // edit date of last payment
    cout << "Edit Date of Last Payment: \n";
    cin >> customers_array[customer_to_edit - 1].dateOfLastPayment;

}

Aucun commentaire:

Enregistrer un commentaire