CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: error LNK2019

  1. #1
    Join Date
    Mar 2009
    Posts
    5

    error LNK2019

    Hey guys, I've been working on this program for class for hours now, and I just can't seem to figure out what this error is all about. I know it seems to be a problem with my function declaration, but I don't really understand what the issue is. Can anyone show me what's going on here, and explain the problem? My teacher mentioned this error very briefly, but never went into the cause of it. Please help save my sanity!

    Thank you so much for the help!

    Code:
    #include<iostream>
    #include <iomanip>
    #include <string>
    using namespace std;
    
    // Global Constants (number of rows, number of columns)
    const int MONKEYS = 3;     // number of rows
    const int DAYS = 7;        // number of columns
    
    // main
    //STUDENT CODE BEGINS (main function)
    void displayAverageDaily(const double mf[MONKEYS][DAYS]);
    void displayLeastEaten(const double mf[MONKEYS][DAYS]);
    void displayMostEaten(const double mf[MONKEYS][DAYS]);
    void enterFoodEaten(const double mf[MONKEYS][DAYS]);
    
    //array declaration
    double monkeyFood[MONKEYS][DAYS] = {0};
    
    int main()
    {
       string menu;
       //Set the program loop identifier
       menu = "y";
    
       while (menu == "y" || menu == "Y")
      {
    
       cout << "U11_MonkeyBusiness Project\n";
       enterFoodEaten(monkeyFood);
       displayAverageDaily(monkeyFood);
       displayLeastEaten(monkeyFood);
       displayMostEaten(monkeyFood);
      
       cout << "\nWould you like to run the program again? Press (y,n)" << endl; //program loop to return to menu
       cin >> menu;
      }
      
    
       
       cin.get();
       return 0;
    }
    //STUDENT CODE ENDS
    //******************************************************
    // The enterFoodEaten function gets the amount of food *
    // eaten for each monkey on each day. The values are   *
    // stored in the food array.                           *
    // See directions for expected output format & content.*
    // NOTE: arrays are passed by reference, not by value, *
    // and therefore are read/write, not read only!        *
    //******************************************************
    //STUDENT CODE BEGINS (enterFoodEaten)
    void enterFoodEaten(double monkeyFood[MONKEYS][DAYS])
      {
       for (int x = 0; x < MONKEYS; x++)
        {
          for (int y = 0; y < DAYS; y++)
               {
                cout << "Enter the pounds eaten by monkey number" << x+1<<" ";
                cout << "on Day " << y+1 <<": ";
                cin >> monkeyFood [x][y];
             
              
                if(monkeyFood [x][y] < 0)
                cout<<" Please enter a positive number."<<endl;
               }
             
          }
       return;
       }
    
    //STUDENT CODE ENDS
    //******************************************************
    // The displayAverageDaily function displays the       *
    // average amount of food eaten by the monkeys for     *
    // each day.                                           *
    // See directions for expected output format & content.*
    // NOTE: arrays are passed by reference, not by value, *
    // and therefore are read/write, not read only!        *
    //******************************************************
    //STUDENT CODE BEGINS (displayAverageDaily)
    
    void displayAverageDaily(double monkeyFood[MONKEYS][DAYS])
    
    {
       int accumulator;
       double averageEaten = 0;
       double total = 0;
       for (int col = 0; col < DAYS; col++)
          {
             total = 0;
          for (int row = 0; row < MONKEYS; row++)
             { 
             total += monkeyFood[row][col];
             averageEaten = total / MONKEYS;
             
             cout << "The average amount eaten on day " << (DAYS +1) << "is " << averageEaten << endl;
             }
          
          
          }
          
          return;
    }
    
    
    
    
    //STUDENT CODE ENDS
    //******************************************************
    // The displayLeastEaten function performs two tasks:  *
    //  1. determine the monkey eating the least food      *
    //       in a day, the amount and the day              *
    //  2. displays the results                            *
    // See directions for expected output format & content.*
    // NOTE: arrays are passed by reference, not by value, *
    // and therefore are read/write, not read only!        *
    //******************************************************
    //STUDENT CODE BEGINS (displayLeastEaten)
    
    void displayLeastEaten(double mf[MONKEYS][DAYS])
    {
       double least= 0;
       for (int x = 0; x < MONKEYS; x++)
          for (int y = 0; y < DAYS; y++)
             if (mf[x][y] > least)
                least= mf[x][y];
       
       return;
    }
    
    //STUDENT CODE ENDS
    //******************************************************
    // The displayMostEaten function performs two tasks:   *
    //  1. determine the monkey eating the most food       *
    //       in a day, the amount and the day              *
    //  2. displays the results                            *
    // See directions for expected output format & content.*
    // NOTE: arrays are passed by reference, not by value, *
    // and therefore are read/write, not read only!        *
    //******************************************************
    //STUDENT CODE BEGINS (displayMostEaten)
    
    double displayMostEaten(double mf[MONKEYS][DAYS])
    {
       double most= 0;
       for (int x = 0; x < MONKEYS; x++)
          for (int y = 0; y < DAYS; y++)
             if (mf[x][y] > most)
                most= mf[x][y];
       
       return most;
    }
    
    //STUDENT CODE ENDS

    These are the errors that are given...

    U11_MonkeyBusiness.obj : error LNK2019: unresolved external symbol "void __cdecl displayMostEaten(double const (* const)[7])" (?displayMostEaten@@YAXQAY06$$CBN@Z) referenced in function _main
    U11_MonkeyBusiness.obj : error LNK2019: unresolved external symbol "void __cdecl displayLeastEaten(double const (* const)[7])" (?displayLeastEaten@@YAXQAY06$$CBN@Z) referenced in function _main
    U11_MonkeyBusiness.obj : error LNK2019: unresolved external symbol "void __cdecl displayAverageDaily(double const (* const)[7])" (?displayAverageDaily@@YAXQAY06$$CBN@Z) referenced in function _main
    U11_MonkeyBusiness.obj : error LNK2019: unresolved external symbol "void __cdecl enterFoodEaten(double const (* const)[7])" (?enterFoodEaten@@YAXQAY06$$CBN@Z) referenced in function _main

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: error LNK2019

    You declared
    Code:
    void displayAverageDaily(const double mf[MONKEYS][DAYS]);
    but implemented
    Code:
    void displayAverageDaily(double monkeyFood[MONKEYS][DAYS])
    Same error for the other functions
    Kurt

  3. #3
    Join Date
    Mar 2009
    Posts
    5

    Re: error LNK2019

    Thank you so much. I changed the name I used to pass the array mid way through the project like an idiot, and missed that completely. Thank you for taking the time! I'll learn eventually!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured