CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2015
    Posts
    13

    [RESOLVED] I am trying to figure out why I am receiving "unresolved external symbol"

    This message is appearing for each of my functions. Could someone explain what the issue is and how to fix it/ prevent it in the future?
    Thank You. Here is my code:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    struct airport
    {
    	float numLanded;
    	float numDeparted;
    	float greatestLanded;
    	float leastLanded;
    };
    
    float averageDeparture(airport, int);
    float averageLanded(airport, int);
    int greatestLanded(airport, int);
    int leastLanded(airport, int);
    
    
    int main()
    {
    	string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
    	airport statistics[12];
    	int totalLanded = 0;
    	int totalDeparted = 0;
    	int count;
    	
    		for (count = 9; count < 12; count++)
    		{
    			cout << "Please enter the number of planes that landed in " << months[count] << ": " << endl;
    			cin >> statistics[count].numLanded;
    			cout << "Please enter the number of planes that departed in " << months[count] << ": " << endl;
    			cin >> statistics[count].numDeparted;
    			cout << "Please enter the greatest number of planes that landed on a single day in " << months[count] << ": " << endl;
    			cin >> statistics[count].greatestLanded;
    
    			
    			
    			totalLanded += statistics[count].numLanded;
    			totalDeparted += statistics[count].numDeparted;
    		}
    		
    	
    
    	cout << "The average monthly landings for the year is " << averageDeparture(statistics[count], count) << endl;
    	cout << "The average monthly departures for the year is " << averageLanded(statistics[count], count) << endl;
    	cout << "The total landings for the year is " << totalLanded << endl;
    	cout << "The total departures for the year is " << totalDeparted << endl;
    	cout << "The greatest number of planes that landed in a single day is " << greatestLanded(statistics[count], count) << " which occured in the month of " << months[count] << endl;
    	cout << "The least number of planes that landed in a single day is " << leastLanded(statistics[count], count) << " which occured in the month of " << months[count] << endl;
    
    	system("pause");
    	return 0;
    }
    
    float averageDeparture(airport array[], int pos)
    {
    	float total = array[pos].numDeparted;
    	
    	return (total / 3);
    	
    }
    
    float averageLanded(airport array[], int pos)
    {
    	float total = array[pos].numDeparted;
    	
    
    	return (total / 3);
    
    }
    
    int greatestLanded(airport array[], int pos)
    {
    	int max = 0;
    	for (int i = 1; i < pos; i++)
    	{
    		if (array[i].numLanded > array[i + 1].numLanded)
    		{
    			max = array[i].numLanded;
    			return max;
    		}
    	}
    }
    
    int leastLanded(airport array[], int pos)
    {
    	int min = 0;
    	for (int i = 1; i < pos; i++)
    	{
    		if (array[i].numLanded < array[i + 1].numLanded)
    		{
    			min = array[i].numLanded;
    			return min;
    		}
    	}
    }

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: I am trying to figure out why I am receiving "unresolved external symbol"

    The prototypes should look more like this:

    Code:
    int greatestLanded(airport array[], int pos);
    You have C Style prototypes, but also the first parameter is not right.

    Your definition and your prototype should be the same.
    ahoodin
    To keep the plot moving, that's why.

  3. #3
    Join Date
    Mar 2001
    Posts
    2,529

    Re: I am trying to figure out why I am receiving "unresolved external symbol"

    The compiler is currently looking for a function definition that takes a single airport object. Not an array.
    ahoodin
    To keep the plot moving, that's why.

  4. #4
    Join Date
    Oct 2015
    Posts
    13

    Re: I am trying to figure out why I am receiving "unresolved external symbol"

    I have made the changes but now i am getting a message saying "cannot convert argument 1 from airport to airport[]" on each function now?

  5. #5
    Join Date
    Mar 2001
    Posts
    2,529

    Re: I am trying to figure out why I am receiving "unresolved external symbol"

    try
    Code:
    int greatestLanded(struct airport array[], int pos);
    and make it the same in both places
    ahoodin
    To keep the plot moving, that's why.

  6. #6
    Join Date
    Oct 2015
    Posts
    13

    Re: I am trying to figure out why I am receiving "unresolved external symbol"

    Ok im still getting that message im pretty sure im changing the right things but here is the modified code:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    struct airport
    {
    	float numLanded;
    	float numDeparted;
    	float greatestLanded;
    	float leastLanded;
    };
    
    float averageDeparture(struct airport array[], int pos);
    float averageLanded(struct airport array[], int pos);
    int greatestLanded(struct airport array[], int pos);
    int leastLanded(struct airport array[], int pos);
    
    
    int main()
    {
    	string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
    	airport statistics[12];
    	int totalLanded = 0;
    	int totalDeparted = 0;
    	int count;
    	
    		for (count = 9; count < 12; count++)
    		{
    			cout << "Please enter the number of planes that landed in " << months[count] << ": " << endl;
    			cin >> statistics[count].numLanded;
    			cout << "Please enter the number of planes that departed in " << months[count] << ": " << endl;
    			cin >> statistics[count].numDeparted;
    			cout << "Please enter the greatest number of planes that landed on a single day in " << months[count] << ": " << endl;
    			cin >> statistics[count].greatestLanded;
    
    			
    			
    			totalLanded += statistics[count].numLanded;
    			totalDeparted += statistics[count].numDeparted;
    		}
    		
    	
    
    	cout << "The average monthly landings for the year is " << averageDeparture(statistics[count], count) << endl;
    	cout << "The average monthly departures for the year is " << averageLanded(statistics[count], count) << endl;
    	cout << "The total landings for the year is " << totalLanded << endl;
    	cout << "The total departures for the year is " << totalDeparted << endl;
    	cout << "The greatest number of planes that landed in a single day is " << greatestLanded(statistics[count], count) << " which occured in the month of " << months[count] << endl;
    	cout << "The least number of planes that landed in a single day is " << leastLanded(statistics[count], count) << " which occured in the month of " << months[count] << endl;
    
    	system("pause");
    	return 0;
    }
    
    float averageDeparture(struct airport array[], int pos)
    {
    	float total = array[pos].numDeparted;
    	
    	return (total / 3);
    	
    }
    
    float averageLanded(struct airport array[], int pos)
    {
    	float total = array[pos].numDeparted;
    	
    
    	return (total / 3);
    
    }
    
    int greatestLanded(struct airport array[], int pos)
    {
    	int max = 0;
    	for (int i = 1; i < pos; i++)
    	{
    		if (array[i].numLanded > array[i + 1].numLanded)
    		{
    			max = array[i].numLanded;
    			return max;
    		}
    	}
    }
    
    int leastLanded(struct airport array[], int pos)
    {
    	int min = 0;
    	for (int i = 1; i < pos; i++)
    	{
    		if (array[i].numLanded < array[i + 1].numLanded)
    		{
    			min = array[i].numLanded;
    			return min;
    		}
    	}
    }

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,923

    Re: I am trying to figure out why I am receiving "unresolved external symbol"

    In c++ you don't need to use the word struct when referring to a struct type (or class). So
    Code:
    float averageDeparture(airport array[], int pos);
    and likewise for the function definition.

    Code:
    cout << "The average monthly landings for the year is " << averageDeparture(statistics[count], count) << endl;
    statistics[count] references an element of the array statistics. However the function parameter requires the whole array to be passed so
    Code:
    cout << "The average monthly landings for the year is " << averageDeparture(statistics, count) << endl;
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    Join Date
    Oct 2015
    Posts
    13

    Re: I am trying to figure out why I am receiving "unresolved external symbol"

    Thank You. That fixed the issue I was having.

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,923

    Re: [RESOLVED] I am trying to figure out why I am receiving "unresolved external symb

    A couple of further comments.

    When dealing with an array of a fixed size (statistics) it is usually considered good practice to set the size of the array as a const int variable at the start and use the variable whenever the size of the array is used (eg in a for loop).

    Code:
    const int NOMONTHS = 12;
    Code:
    string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
    As the contents of this array don't change, it would usually be declared as const. Also as the size of months array is known from the const var it can be specified.
    Code:
    const string months[NOMONTHS] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
    Code:
    for (count = 9; count < 12; count++)
    becomes
    Code:
    for (count = 9; count < NOMONTHS; count++)
    I'm assuming for test purposes that you are starting at 9 rather then 0?

    Code:
    return (total / 3);
    Why 3? As your loop is only going from 9 to 11 then you only enter 3 sets of data, but hard coding a number like this in code leads to errors. What if you make the original for loop start at 6?

    If you want code like this IMO I would use another const variable for number required. Something like this
    Code:
    const int REQ = 3;
    ...
    for (count = NOMONTHS - REQ; count < NOMONTHS; count++)
    ...
    return (total / REQ);
    That way if you change REQ to be what is wanted then it is right all through the program.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

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