LNK2001 error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • labonte373
    New Member
    • Sep 2006
    • 1

    LNK2001 error

    Hello. I am trying to complete a class project. My code compiles but will not link. I keep getting the following error:

    Linking...
    p9-4-4.obj : error LNK2001: unresolved external symbol "void __cdecl Load_Student_Ta ble(struct TABLE_STRUCT * const,int)" (?Load_Student_ Table@@YAXQAUTA BLE_STRUCT@@H@Z )
    Debug/p9-4-4.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    My program is as follows:

    Code:
    //p9-4-4.cpp
    
    // This program will request information from the user
    // and will calculate averages, then will display results.
    
    #include<iostream>
    #include<iomanip>
    #include<string>
    #include<cstring>
    
    using namespace std;
    
    
    struct TABLE_STRUCT
    {
    	char student_string[25];
    	int  Avg_Quiz;
    	int  Fin_Grade;
    	double  final_avg;
    };
    void   Load_Student_Table(TABLE_STRUCT [], const int);
    void   Display_Student_Table(TABLE_STRUCT [], const int);
    
    
    int main()
    {
    	const int TABLE_SIZE = 25;
    	TABLE_STRUCT student_table[TABLE_SIZE];
    	int row = 25;
    	const int NUM_STUDENTS =25;
    	const int NUM_QUIZZES = 5;
    	const double QUIZ_WEIGHT = 0.75;
    	const double EXAM_WEIGHT = 0.25;
    	int student_grades[NUM_QUIZZES][NUM_STUDENTS];
    	int quiz,
    		quiz_sum,
    		student =1,
    		exam_grade = 0;
    	char student_string[25];
    
    	char response[12];
    
    
    	double quiz_avg;	//Average for the 5 quizzes
    	double final_avg;
    
    	// Setup output stream for one decimal place
    
    	cout << setprecision(1)
    	     << setiosflags(ios::fixed)
    		 << setiosflags(ios::showpoint);
    
    	cout <<"       ************Welcome to Marketing 101************       ";
    	// Load the table
    	Load_Student_Table(student_table, TABLE_SIZE);
    
    	for (row = 0; row < TABLE_SIZE; ++row)
    	{
    		cout << endl;
    		cout << "For row #" << row +1 << "enter:" << endl;
    		cout << "Student Name:";
    		cin.getline(student_table[row].student_string, 25);
    
    		cout << "Quiz Average:";
    		cin >> student_table[row].Avg_Quiz;
    
    		cout << "Exam Grade:";
    		cin >> student_table[row].Fin_Grade;
    
    		cout << "Final Average:";
    		cin >> student_table[row].final_avg;
    
    		cin.get();
    	}
    	
    	cout << "Enter the student's full name:\t\t";
    	cin.getline(student_string, 30);
    	cout << endl;
    
    	cout << "Enter the students social:\t\t";
    	cin.getline(response,12);	
    	cout << endl;
    
    	cout << "Enter the students telephone number: \t";
    	cin.getline(response,12);
    	cout << endl;
    
    	
    	cout << "Enter exactly " << NUM_QUIZZES
    		 << "  quiz grades for each student." << endl;
    	cout << "Separate the grades by one or more spaces." << endl;
    
    	
    	for(student =0; student < NUM_STUDENTS; ++student)
    	{
    		cout << endl << endl;
    		cout << "Grades for    " << student_string + 0 <<":";
    		for(quiz = 0; quiz < NUM_QUIZZES; ++quiz)
    			cin >> student_grades[quiz][student];
    	}
    
    	for (student =0; student < NUM_STUDENTS; ++student)
    	{
    		quiz_sum =0;
    		for (quiz =0; quiz < NUM_QUIZZES; ++quiz)
    			quiz_sum += student_grades[quiz][student];
    
    		quiz_avg = (double) quiz_sum / NUM_QUIZZES;
    	}
    
    	cout << endl << endl;
    
    
    	cout << "Enter the final exam grade:  " ;
    	cin >> exam_grade;
    	cout << endl;
    
    	final_avg = EXAM_WEIGHT * exam_grade + QUIZ_WEIGHT * quiz_avg;
    	return final_avg;
    
    	//End of load table
    
    	//Display the table
    	cout <<endl << endl;
    	cout << "This is the table you entered.";
    
    	void Display_Student_Table(TABLE_STRUCT student_table[], int size);
    	{
    		int row;
    
    		cout << endl << endl;
    		cout << setw(3)  << "Quiz Avg."
    			 << setw(2)  << "Exam Grade"
    			 << setw(1)  << "Final Avg." << endl;
    		for (row =0; row < TABLE_SIZE; ++row)
    		{
    			cout << endl;
    			cout << setw(3)  << student_table[row].Avg_Quiz
    				 << setw(2)  << student_table[row].Fin_Grade
    				 << setw(1)  << student_table[row].final_avg;
    		}
    	}
    
    
    	//Display final average, quiz average, and final exam grade
    	cout << "The quiz average is: \t" << quiz_avg << endl;
    	cout << "The final exam grade is:\t" << exam_grade << endl;
    	cout << "The final average is:\t" << final_avg << endl;
    
    	return 0;
    }
    Last edited by Banfa; Sep 4 '06, 08:06 AM. Reason: Added code tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You have 2 major and obvious(to me) problems

    1. Load_Student_Ta ble - you have declared and call this function but you have not implemented it anywhere, it is not defined. This is why you are getting the linker error the linker can not find the function Load_Student_Ta ble

    2. Display_Student _Table - you have declared this function but not called it. However you have tried to implement it, however you have done so in the middle of the function main. You can not define a function inside another function. The reason it compiles is that you have a semi-colon at the end of the function definition

    void Display_Student _Table(TABLE_ST RUCT student_table[], int size);

    this makes it a declaration which is valid and the following code just becomes part of the main function.

    Comment

    Working...