0

The Unresolved external symbol error is preventing the compilation of my code. It specifically is mentioning two functions being called in main. The functions are a part of a switch I am trying to create and it is still under construction. If anyone has any suggestions for how I can fix the bug or improve my code please let me know and thank you in advance. FYI- I already searched for similar questions and they are not specific to my problem...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//This is a macro intended for use with the emplyName array.
#define SIZE 20 

//This struct has all the varibles that I will be using in my functions
typedef struct person
{
    char* emplyName[5][SIZE];
    float emplyHours[5];
    float emplyRate[5];
    float emplyGross[5];
    float emplyBase[5];
    float emplyOvrt[5];
    float emplyTax[5];
    float emplyNet[5];
    float emplyTotal[5];
}input;

void menu(void);
void employeeInfo(input* emply);
void editEmployees(input* emply);
void print(input* emply);

int main(void)
{
    struct person *payroll={""};
    int choice = 0;
    menu();
    scanf_s("%c", &choice);
    switch (choice){
    case '1':
        employeeInfo(payroll);
        break;
    case '2':
        editEmployees(payroll);
        break;
    case '3':
        print(payroll);
        break;
    case '4':
        break;
    default:
        printf("Invalid entry\n");
    }
    system("pause");
}

void employeeInfo(input *emply)
{
    int i=0;
    do {
        printf("Enter employee name.\n");
        scanf_s("%s", &emply->emplyName[i]);
        printf("Enter employee hours.\n");
        scanf_s("%f", &emply->emplyHours[i]);
        printf("Enter Hourly rate.\n");
        scanf_s("%f", &emply->emplyRate[i]);
    } while (++i <= 5);

    void calculations(input *emply);/*Write a method that calculates the gross, base and overtime pay, pass by reference.*/
{
    int i;
    i = 0;
    for (i = 0; i < 5; i++){
        if (emply->emplyHours[i] > 40) {
            emply->emplyOvrt[i] = (emply->emplyHours[i] - 40) * (emply->emplyRate[i] * 1.5);
        }
        emply->emplyGross[i] = (((emply->emplyHours[i])*(emply->emplyRate[i])) + emply->emplyOvrt[i]);
        emply->emplyBase[i] = (emply->emplyGross[i]) - (emply->emplyOvrt[i]);
        emply->emplyTax[i] = ((emply->emplyGross[i])*.2);
        emply->emplyNet[i] = (emply->emplyGross[i]) - (emply->emplyTax[i]);
        emply->emplyTotal[0] += emply->emplyGross[i];
    }


}


void print(input *emply);
{
    int i;
    for (i = 0; i < 5; i++)
    {


        printf("Employee Name:%s\n", emply->emplyName[i]);
        printf("Hours Worked:%.2f\n ", emply->emplyHours[i]);
        printf("Hourly Rate:%.2f\n", emply->emplyRate[i]);
        printf("Gross Pay:%.2f\n", emply->emplyGross[i]);
        printf("Base Pay:%.2f\n", emply->emplyBase[i]);
        printf("Overtime Pay:%.2f\n", emply->emplyOvrt[i]);
        printf("Taxes Paid:%.2f\n", emply->emplyTax[i]);
        printf("Net Pay:%.2f\n", emply->emplyNet[i]);
    }
    printf("Total paid to all employees : %.2f\n", emply->emplyTotal[0]);
}
void editEmployees(input*emply);
{
    char edit;
    int i;
    printf("which employee would you like to edit?\n");
    for (i = 0; i < 5; i++){
        printf("%d.%s", i + 1, emply->emplyName[i]);
    }
    scanf_s("%c", &edit);
    switch (edit){
    case '1':
        printf("Enter employee name.\n");
        scanf_s("%s", &emply->emplyName[0]);
        printf("Enter employee hours.\n");
        scanf_s("%f", &emply->emplyHours[0]);
        printf("Enter Hourly rate.\n");
        scanf_s("%f", &emply->emplyRate[0]);
    }
}



}

void menu(void){
    printf("Main Menu\n");
    printf("1. Add Employee\n");
    printf("2. Edit Employee\n");
    printf("3. Print Employee\n");
    printf("4. Print All EMployees\n");
    printf("0. exit\n");

}
lvlayhelvl
  • 19
  • 6
  • 1
    `scanf_s("%c", &choice);`...how? why? – Sourav Ghosh Aug 01 '15 at 17:50
  • 3
    It would help if you gave us the *exact* error message, rather than leaving us to guess... – Oliver Charlesworth Aug 01 '15 at 17:50
  • Error 4 error LNK2019: unresolved external symbol _editEmployees referenced in function _main C:\Users\jzapa_000\Desktop\Assignment4\Assignment4\Assignment_4.obj Assignment4 – lvlayhelvl Aug 01 '15 at 17:51
  • Error 5 error LNK2019: unresolved external symbol _print referenced in function _main C:\Users\jzapa_000\Desktop\Assignment4\Assignment4\Assignment_4.obj Assignment4 – lvlayhelvl Aug 01 '15 at 17:52
  • @SouravGhosh what seems to be the problem with that ? – lvlayhelvl Aug 01 '15 at 17:52
  • 1
    see [this](https://msdn.microsoft.com/en-us/library/w40768et.aspx) first. – Sourav Ghosh Aug 01 '15 at 17:55
  • You do not get an undefined symbol error for `employeeInfo()`? – alk Aug 01 '15 at 17:59
  • Post less code please. Take the time to strip away as much as possible, to not bother us with lines that don't matter. – meaning-matters Aug 01 '15 at 18:01
  • There is no unresolved external error for employeeInfo only for the editEmployee and Print.... If I comment them out it will compile but the editEmployee function should work.... – lvlayhelvl Aug 01 '15 at 18:02
  • @lvlayhelvl Yes, I didn't scroll down far enough to see the implementation of `editEmployees`. You have a misplaced closing brace `}`. The closing brace before the `menu` function should be deleted, and you need a closing brace before the `calculations` function. – user3386109 Aug 01 '15 at 18:09
  • The reason for the linker error in this case is a subtile and unusual one, which is not being covered by the answers to the question this question was closed as being a dupelicate too. I therefor reopen this question. – alk Aug 01 '15 at 18:45

1 Answers1

6

You defined editEmployees() and print() local to employeeInfo().

  1. This hides them from the the rest of the program.
  2. This is not Standard C.
  3. If you'd indented your code properly you most probably would have noticed this yourself.

Same for calculations().

alk
  • 69,737
  • 10
  • 105
  • 255