Help with "undefined symbol main" error for a function assignment

Hi,
I am getting the following error when I try to compile:
Undefined first referenced
symbol in file
getUserChoice() /var/tmp//ccdG6UVN.o
ld: fatal: symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


I have looked it up online and am guessing that it is a library linker error, but I do not know how to fix it. I am wondering why it is saying there is an error with getUserChoice() and not getComputerChoice as they are written and used in the same way. Any help or explanation would be appreciated. This is for a class I am taking in c++ so I am at a very "beginner level" and still trying to understand everything. Thank you for your time!




#include <iostream>
#include <string>

using namespace std;

// Functions used for program

void displayGameDetails();

void playGame();

string getComputerChoice();

string getUserChoice();

string getChoiceAsString(int);

void displayChoices(string, string);

string findWinner(string, string);

int main()

{

displayGameDetails();


playGame();

system("pause");

return 0;

}

void displayGameDetails()
{
cout << "Lets play rock paper scissors!" << endl;
"ajanch6project.cpp" 134 lines, 2303 characters
{
cout << "Lets play rock paper scissors!" << endl;
}

void playGame()
{
string computerChoice;
string userChoice;
string gameWinner;

computerChoice = getComputerChoice();
userChoice = getUserChoice();
displayChoices(computerChoice, userChoice);
gameWinner = findWinner(computerChoice, userChoice);
if(gameWinner !="")
cout << "The winner of this game is " << gameWinner<< endl;
}

string getComputerChoice()
{
int comp;
string cmpChoice;
unsigned seedTime=time(0);
srand(seedTime);
comp=1+rand()%3;
cmpChoice = getChoiceAsString(comp);
return cmpChoice;
}

string GetUserChoice()
{
int usr;
string usrChoice;

cout << "The computer has already chosen, now it is your turn" << endl;
cout << "Type 1 for Rock, 2 for Paper, 3 for Scissors" << endl;
cin >> usr;
while(usr!=1 && usr!=2 && usr!=3)
{
cout << "Invalid, enter 1, 2, or 3 only" << endl;
cin >> usr;
}
usrChoice = getChoiceAsString(usr);
return usrChoice;
}

string getChoiceAsString(int choice)
{
if(choice == 1)
return "Rock";
else if(choice == 2)
return "Paper";
else // choice == 3
return "Scissors";
return "Scissors";
}

void displayChoices(string comp, string usr)
{
cout << "The computer choice: " << comp << endl;
cout << "The user choice: " << usr << endl;
}

string findWinner(string comp, string usr)
{
string computer = "Computer";
string user = "User";
string winner;

if(comp == "Rock" && usr == "Scissors")
winner=computer;
else if (comp == "Rock" && usr=="Paper")
winner=user;
else if(comp =="Paper" && usr =="Rock")
winner=computer;
else if(comp == "Paper" && usr=="Scissors")
winner=user;
else if(comp =="Scissors" && usr =="Paper")
winner=computer;
else if(comp == "Scissors" && usr =="Rock")
winner=user;
else
{
cout << "The game is a tie." << endl;
cout << "Play again please" << endl;
playGame();
}
return winner;
}




Last edited on
Thank you ! ! ! ! ! ! !
Topic archived. No new replies allowed.