0

When I try to compile, I get only two error messages.

"Error LNK2019 unresolved external symbol "int __cdecl examAvg(void)" (?examAvg@@YAHXZ) referenced in function _main

Line 1

and

LNK1120 1 unresolved externals

also on Line 1

I have worked on this so long (days) that I really can't figure out where I am going wrong anymore, I am sure it is something simple, but I am for a loss again.

Will someone please give me a suggestion to help rectify the error codes?

/*
    Christopher Pierce

Date Created: July 3, 2020

Egrades Vector Application

*This application creates a C++ menu program that generates an electronic grade sheet that can keep track of five student test scores earned during the semester.

• Organizes the main program menu to call four functions.
• (1) function that allow a user to Add five students and their scores on three exams into the vector.
• (2) function that will compute the average test score for each of the five students in the vector.
• (3) function that all the user to display a student average test scores searching for their name in the vector.
• (4) function that will compute the average of the average exams in the vector and display the result.
*/

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

// Declarations

int score1;
int score2;
int score3;
int score4;
int score5;
int score6;
int score7;
int score8;
int score9;
int score10;
int score11;
int score12;
int score13;
int score14;
int score15;

string student1;
string student2;
string student3;
string student4;
string student5;

int main()

{

    vector <string> StudentFile;
    vector <int> Egrades;


    int average1 = (score1 + score2 + score3) / 3;
    int average2 = (score4 + score5 + score6) / 3;
    int average3 = (score7 + score8 + score9) / 3;
    int average4 = (score10 + score11 + score12) / 3;
    int average5 = (score13 + score14 + score15) / 3;

    // Prototype (functions)

    int examAvg();
    {
        StudentFile.insert(StudentFile.begin(), student1);
        Egrades.insert(Egrades.begin(), average1);

        StudentFile.push_back(student2);
        Egrades.push_back(average2);

        StudentFile.push_back(student3);
        Egrades.push_back(average3);

        StudentFile.push_back(student4);
        Egrades.push_back(average4);

        StudentFile.push_back(student5);
        Egrades.push_back(average5);
    }
    /*
    

    Start of Menu
    

    */
     
    // Defines the width of the menu
    const int menuWidth = 84;

    // This is a loop structure for the menu box using ASCII
    // This prints the top left corner of the menu box (ASCII)
    cout << char(201);

    // This prints the top border of the menu box (ASCII)
    for (int column = 0; column < menuWidth; ++column) {
        cout << char(205);
    }

    // This prints the top right corner of the menu box (ASCII)
    cout << char(187);
    cout << "\n";

    // array with menu options
    string menu[15];
    menu[0] = "                                 **************";
    menu[1] = "                              ***  MAIN  MENU  ***";
    menu[2] = "                                 **************";
    menu[3] = "                    Please Choose From The Following Options:";
    menu[6] = "  1. Add 5 Students to Egrades Vector:";
    menu[8] = "  2. Compute Student Test Score Average:";
    menu[10] = "  3. Search A Student Average Test Score:";
    menu[12] = "  4. Compute The Average Of All 5 Student Exam Averages:";
    menu[14] = "  5. Exit";


    for (string option : menu)
    {
        cout << char(186) // print left border
            << setw(menuWidth) // set next item width
            << left // set next item aligment
            << option // print menu option string with width and aligment
            << char(186) << "\n"; // print right border
    }

    // This will print the bottom left corner of the menu box (ASCII)
    cout << char(200);

    // This prints the bottom border of the menu box (ASCII)
    for (int column = 0; column < menuWidth; ++column) {
        cout << char(205);
    }

    // This prints the bottom right corner of the menu box (ASCII)
    cout << char(188);
    cout << "\n\n";

    /*


    END OF MENU


     */

    char selection;

    cout << "\t\t\t     Enter Your Selection: ", cin >> selection, cout << endl;

        switch (selection)

        {

        case '1':

            system("CLS");

                    cout << "Student Information Section:\n\n";

                    // Student 1 Info, captures name and scores        

                    cout << "\nEnter Student 1 Name: \n";

                    cin >> student1;

                    cout << "\nEnter Exam 1 Score: ";
                    cin >> score1;
                    cout << "Enter Exam 2 Score: ";
                    cin >> score2;
                    cout << "Enter Exam 3 Score: ";
                    cin >> score3; examAvg();

                    // Student 2 Info, captures name and scores        

                    cout << "\nEnter Student 2 Name:\n";

                    cin >> student2;

                    cout << "\nEnter Exam 1 Score: ";
                    cin >> score4;
                    cout << "Enter Exam 2 Score: ";
                    cin >> score5;
                    cout << "Enter Exam 3 Score: ";
                    cin >> score6; examAvg();

                    // Student 3 Info, captures name and scores        

                    cout << "\nEnter Student 3 Name:\n";

                    cin >> student3;

                    cout << "\nEnter Exam 1 Score: ";
                    cin >> score7;
                    cout << "Enter Exam 2 Score: ";
                    cin >> score8;
                    cout << "Enter Exam 3 Score: ";
                    cin >> score9; examAvg();

                    // Student 4 Info, captures name and scores        

                    cout << "\nEnter Student 4 Name:\n";

                    cin >> student4;

                    cout << "\nEnter Exam 1 Score: ";
                    cin >> score10;
                    cout << "Enter Exam 2 Score: ";
                    cin >> score11;
                    cout << "Enter Exam 3 Score: ";
                    cin >> score12; examAvg();

                    // Student 5 Info, captures name and scores        

                    cout << "\nEnter Student 5 Name:\n";

                    cin >> student5;

                    cout << "\nEnter Exam 1 Score: ";
                    cin >> score13;
                    cout << "Enter Exam 2 Score: ";
                    cin >> score14;
                    cout << "Enter Exam 3 Score: ";
                    cin >> score15; examAvg();
                  
                
                cout << "\n\n******************************************************\n";
                cout << "!!!  INFORMATION HAS BEEN ADDED TO EGRADES VECTOR  !!!\n";
                cout << "******************************************************\n\n";
                cout << "To Return To Main Menu:\n\n";
                system("pause");

                    return main(); 

            break;
                
        case '2':

            system("CLS");

            
            for (unsigned int i = 0; i < Egrades.size(); ++i)
            {
                cout << Egrades[i] << endl;
            }
            
            cout << "To Return To Main Menu:\n\n";
            system("pause");
            return main();

                break;
            

        case '3':

            system("CLS");

            int score;
            cout << "\nEnter A Students Name To Find Their Average:\n";
            cin >> score;

            if (cin >> student1)

            {
                cout << "Average Found:\n" << average1;
            }
            else if (cin >> student2)
            {
            
                cout << "Average Found:\n" << average2;
            
            }
            else if (cin >> student3)
            {
                
                cout << "Average Found:\n" << average3;

            }
            else if (cin >> student4)
            {

                cout << "Average Found:\n" << average4;

            }
            else if (cin >> student5)
            {

                cout << "Average Found:\n" << average5;

            }
            else
            {
                cout << "Average not found.\n";
            }

            cout << "To Return To Main Menu:\n\n";
            system("pause");
            return main();

            break;

        case '4':

            system("CLS");

            cout << "The Average of All Five Students Averages Are:\n\n";
            cout << "||  " << (average1 + average2 + average3 + average4 + average5) / 5 << "  ||\n\n";

            cout << "To Return To Main Menu:\n\n";
            system("pause");
            return main();

            break;

        case '5':

            exit(-1);

            break;

        default: cout << "\n Invalid selection\n\n";

        }

    return 0;

}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Pierce2307
  • 41
  • 2
  • 1
    Why you write `int examAvg();` inside of the main function? You must write prototypes BEFORE `main`, not inside... – Georgy Firsov Jul 11 '20 at 09:26
  • 1
    Protoypes do not belong inside the main function. – fxweidinger Jul 11 '20 at 09:29
  • 1
    Sounds like you're really confused about functions and function arguments. You might want to invest some time into reading a good [C++ Book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Will save a ton of time. – rustyx Jul 11 '20 at 09:35
  • 1
    Declare the function outside of the main. Then call it from inside the main function. Also: if your function returns int, you probably should use its return value. – fxweidinger Jul 11 '20 at 09:37
  • Thank you all for your comments and help, I resolved it outside of the main function as suggested. Also, yes, I will certainly invest in a good C++ book. My professor has not been the most helpful, so I have almost been on my own learning this. Truly, I appreciate everyone' s help and input. – Pierce2307 Jul 11 '20 at 10:31

0 Answers0