I am making a trivia game that consist of 10 questions. I am using a class to make an array of 10 objects. I have the program all written out but when I compile I get two errors. Error 1 error LNK2019: unresolved external symbol "void __cdecl displayGame(class Game,int)" (?displayGame@@YAXVGame@@H@Z) referenced in function _main
The other error is Error 2 error LNK1120: 1 unresolved externals

Does anybody have a clue what can be causing the errors? Thanks in advance!

.h FILE looks like this :

#ifndef GAME_H
#define GAME_H


#include <string>
using namespace std;

class Game {
private:
	string question;
	string answer1;
	string answer2;
	string answer3;
	string answer4;
	int correctnum;
public:
	//mutators
	void setQues(string ques)
	{question = ques;}
	void setAnswer1(string one)
	{answer1 = one;}
	void setAnswer2(string two)
	{answer1 = two;}
	void setAnswer3(string three)
	{answer1 = three;}
	void setAnswer4(string four)
	{answer1 = four;}
	void setCorrect(int right)
	{correctnum = right;}

	//accessors
	string getQues() const
	{ return question;}
	string getAnswer1() const
	{ return answer1;}
	string getAnswer2() const
	{ return answer2;}
	string getAnswer3() const
	{ return answer3;}
	string getAnswer4() const
	{ return answer4;}
	int getCorrect() const
	{return correctnum;}
};



#endif

My .cpp FILE looks like this :

#include "Game.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

void displayGame(Game, int);

int main() {//start main
	Game trivia[10]; //creating 10 instances of Game class
	int count = 0; //used to count through loop and as index
	//variables to hold players answers
	int onechoice; 
	int twochoice;
	//holds total points for each player
	int onePoints = 0;
	int twoPoints = 0;

	int x;

	cout << "This Trivia Game consist of football questions." << endl;
	cout << "The player with the best score at the end WINS!!!!!" << endl;
	//creating questions and answer in each object
    // QUESTION ONE   
	trivia[0].setQues("How many quarters are in a football game?");
		trivia[0].setAnswer1("1.  4)");
		trivia[0].setAnswer2("2.  1)");
		trivia[0].setAnswer3("3.  3)");
		trivia[0].setAnswer4("4.  2)");
		trivia[0].setCorrect(1);

		// QUESTION TWO  
	trivia[1].setQues("How many points is a Touchdown?");
		trivia[1].setAnswer1("1.  2)");
		trivia[1].setAnswer2("2.  6)");
		trivia[1].setAnswer3("3.  10)");
		trivia[1].setAnswer4("4.  7)");
		trivia[1].setCorrect(2);

		// QUESTION THREE  
	trivia[2].setQues("How many points is a PAT?");
		trivia[2].setAnswer1("1.  2)");
		trivia[2].setAnswer2("2.  7)");
		trivia[2].setAnswer3("3.  6)");
		trivia[2].setAnswer4("4.  1)");
		trivia[2].setCorrect(4);

		// QUESTION FOUR   
	trivia[3].setQues("When the Quarterback is tackled behind the line of scrimmage it is called a...?");
		trivia[3].setAnswer1("1.  sack)");
		trivia[3].setAnswer2("2.  safety)");
		trivia[3].setAnswer3("3.  PAT)");
		trivia[3].setAnswer4("4.  interception)");
		trivia[3].setCorrect(1);

		// QUESTION FIVE  
	trivia[4].setQues("What happens when both teams are tied after regulation?");
		trivia[4].setAnswer1("1. Game is over)");
		trivia[4].setAnswer2("2.  They play paper football to find out the winner.)");
		trivia[4].setAnswer3("3.  Overtime)");
		trivia[4].setAnswer4("4.  They replay the game.)");
		trivia[4].setCorrect(3);

		// QUESTION SIX   
	trivia[5].setQues("The championship game is called the...?");
		trivia[5].setAnswer1("1.  Superbowl)");
		trivia[5].setAnswer2("2.  World Series)");
		trivia[5].setAnswer3("3.  Stanley Cup)");
		trivia[5].setAnswer4("4.  Nothing, there is no championship game.)");
		trivia[5].setCorrect(1);

		// QUESTION SEVEN   
	trivia[6].setQues("The Runningback is also called the what?");
		trivia[6].setAnswer1("1.  Quarterback)");
		trivia[6].setAnswer2("2.  Halfback)");
		trivia[6].setAnswer3("3.  Cornerback)");
		trivia[6].setAnswer4("4.  Wideout)");
		trivia[6].setCorrect(2);

		// QUESTION EIGHT   
	trivia[7].setQues("How many weeks are in the regular season?");
		trivia[7].setAnswer1("1.  16)");
		trivia[7].setAnswer2("2.  17)");
		trivia[7].setAnswer3("3.  11)");
		trivia[7].setAnswer4("4.  52)");
		trivia[7].setCorrect(2);

		// QUESTION NINE   
	trivia[8].setQues("How many games does a team play in the regular season?");
		trivia[8].setAnswer1("1.  16)");
		trivia[8].setAnswer2("2.  17)");
		trivia[8].setAnswer3("3.  10)");
		trivia[8].setAnswer4("4.  50)");
		trivia[8].setCorrect(1);

		// QUESTION TEN   
	trivia[9].setQues("The Giants are from what city?");
		trivia[9].setAnswer1("1.  Dallas)");
		trivia[9].setAnswer2("2.  Texas)");
		trivia[9].setAnswer3("3.  New York)");
		trivia[9].setAnswer4("4.  LA)");
		trivia[9].setCorrect(3);


	while(count < 9, count++) {//start while   loop for actual game
		
		cout << setw(10) << " QUESTION " << (count + 1) << endl;
		
		displayGame(trivia[count],count);  //displaying current question
		//allowing players to choose answers
		cout << "Player 1's answer: ";
		cin >> onechoice;
		cout << "Player 2's answer: ";
		cin >> twochoice;

		//if statements check to see if answers are right, if they are right then they get a point 
		if(trivia[count].getCorrect() == onechoice) { 
			onePoints++;
		}
		if(trivia[count].getCorrect() == twochoice) {
			twoPoints++;
		}

		cout << endl << endl;
	}//end while

	// if and elses check to see which player is the winner or if they are tied
	if ( onePoints == twoPoints) {
		cout << "Both players were tied." << endl;
	}

	if ( onePoints > twoPoints) {
		cout << "PLAYER ONE IS THE WINNER!!!!!!" << endl;
	}else {
		cout << "PLAYER TWO IS THE WINNER!!!!!!" << endl;
	}


	cout << "Thanks for playing, press any key to exit.";
	cin >> x;
}//end main


void displayGame(Game z[], int count) {  //function to display each question along with answers
	
	cout << z[count].getQues() << endl;
	cout << z[count].getAnswer1() << endl;
	cout << z[count].getAnswer2() << endl;
	cout << z[count].getAnswer3() << endl;
	cout << z[count].getAnswer4() << endl;

}

The prototype of displayGame needs to match its definition _exactly_. So you need this prototype instead (at the beginning):

void displayGame(Game[], int);

The prototype of displayGame needs to match its definition _exactly_. So you need this prototype instead (at the beginning):

void displayGame(Game[], int);

That does solve the problem of the two errors. But it also creates another one. Error 1 error C2664: 'displayGame' : cannot convert parameter 1 from 'Game' to 'Game []'

Any other pieces of advice?

If you do not follow what your clients want, or text book wants you failed and I know this program and you made a choice to chansge it. You where so close.

This article has been dead for over six months. Start a new discussion instead.