All i am getting is undefined reference. I dont know if i am using header files the wrong way or not.
Well all the function are coming up as undefined reference.
1 2 3 4 5 6 7 8 9 10 11 12
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `initialPrompt()'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `setUpGame(int)'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `setUpGuesser(int, charconst*)'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `guessACharacter()'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `guessHasBeenMade(char)'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `guesserHasWon()'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `guesserHasLost()'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `guesserHasWon()'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `providerHasLost()'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `providerHasWon()'|
C:\Users\x\Desktop\hangman.o:hangman.cpp|| undefined reference to `admitToLoss(std::string)'|
||=== Build finished: 11 errors, 0 warnings (0 minutes, 0 seconds) ===|
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include "game.h"
#include "guesser.h"
#include "provider.h"
usingnamespace std;
bool charactersTried[26];
string* possibleSolutions;
int numPossibleSolutions;
int numMissedGuesses;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
/**
* Guesser has lost the game. Look at the provider's actual word
* and gripe a bit about losing.
*/
void admitToLoss (std::string actualWord)
{
bool match = actualWord.size() == wordSoFar.size();
for (int i = 0; match && i < actualWord.size(); ++i)
{
match = wordSoFar[i] == FILL_CHARACTER || wordSoFar[i] == actualWord[i];
}
if (!match)
{
cout << "Ummm...your word '" << actualWord
<< "' does not match the patterh '"
<< wordSoFar <<"'.\nDid you make a mistake somewhere?"
<< endl;
}
else
{
for (int i = 0; match && i < actualWord.size(); ++i)
{
if (wordSoFar[i] == FILL_CHARACTER
&& charactersTried[actualWord[i]-'a'])
{
cout << "Did you forget to mention the '"
<< actualWord[i]
<< "' in position " << i+1 << "?"
<< endl;
return;
}
}
for (int i = 0; (!match) && i < numPossibleSolutions; ++i)
match = (actualWord == possibleSolutions[i]);
match = match && (numPossibleSolutions > 0);
if (match)
{
cout << "OK, I might have guessed that eventually." << endl;
}
else
{
cout << "Interesting, I don't know that word. Are you sure you\n"
<< "spelled it correctly?." << endl;
}
}
}
void characterIsInWord (char guess, const string& wordSoFar)
{
string* remainingSolutions = new string[numPossibleSolutions];
int numRemainingSolutions = 0;
for (int i = 0; i < numPossibleSolutions; ++i)
{
string wd = possibleSolutions[i];
bool OK = true;
for (int k = 0; OK && k < wordSoFar.size(); ++k)
{
if (wordSoFar[k] == guess)
{
if (wd[k] != guess)
{
OK = false;
}
}
}
if (OK)
{
//cerr << "Keeping " << wd << endl;
remainingSolutions[numRemainingSolutions] = wd;
++numRemainingSolutions;
}
}
delete [] possibleSolutions;
possibleSolutions = remainingSolutions;
numPossibleSolutions = numRemainingSolutions;
// cerr << numRemainingSolutions << "possibilities left" << endl;
}
void characterIsNotInWord (char guess)
{
string* remainingSolutions = new string[numPossibleSolutions];
int numRemainingSolutions = 0;
for (int i = 0; i < numPossibleSolutions; ++i)
{
string wd = possibleSolutions[i];
if (wd.find(guess) == string::npos)
{
remainingSolutions[numRemainingSolutions] = wd;
++numRemainingSolutions;
}
}
delete [] possibleSolutions;
possibleSolutions = remainingSolutions;
numPossibleSolutions = numRemainingSolutions;
// cerr << numRemainingSolutions << "possibilities left" << endl;
}
char guessACharacter()
{
int counts[26];
for (int i = 0; i < 26; ++i)
counts[i] = 0;
// Count the number of words in which each letter can be found
for (int i = 0; i < numPossibleSolutions; ++i)
{
string word = possibleSolutions[i];
for (char c = 'a'; c <= 'z'; ++c)
{
if (!charactersTried[c- 'a'])
{
// Character c has not been tried yet
if (word.find(c) != string::npos)
// c is in this word
++counts[c - 'a'];
}
}
}
// Find the character that occurs in the most words
char guess = ' ';
int maxSoFar = -1;
for (char c = 'a'; c <= 'z'; ++c)
{
if (counts[c - 'a'] > maxSoFar)
{
guess = c;
maxSoFar = counts[c - 'a'];
}
}
if (maxSoFar <= 0)
{
guess = 'a';
while (charactersTried[guess-'a'])
++guess;
}
charactersTried[guess-'a'] = true;
return guess;
}
bool guesserHasLost()
{
return numMissedGuesses >= MAX_MISTAKE_LIMIT;
}
bool guesserHasWon()
{
return wordSoFar.find(FILL_CHARACTER) == string::npos;
}
void setUpGuesser (int wordLength, constchar* wordListFilename)
{
for (int i = 0; i < 26; ++i)
charactersTried[i] = false;
constint MAXWORDS = 25000;
possibleSolutions = new string[MAXWORDS];
numPossibleSolutions = 0;
string word;
ifstream in (wordListFilename);
while (in >> word)
{
if (word.size() == wordLength)
{
// word is of desired length
if (word.find_first_not_of(alphabet) == string::npos) {
// word contains only lowercse alphabetics
possibleSolutions[numPossibleSolutions] = word;
++numPossibleSolutions;
}
}
}
in.close();
}
bool getYesNoResponse()
{
string response;
getline (cin, response);
while (response.size() == 0 ||
(response[0] != 'y' && response[0] != 'Y'
&& response[0] != 'n' && response[0] != 'N'))
{
if (response.size() > 0)
cout << "Please respond 'yes' or 'no'. " << flush;
getline (cin, response);
}
return response[0] == 'y' || response[0] == 'Y';
}
OP, what are you using to build your code? Are you telling your compiler to build all of these files? It is not enough to just open the files in an IDE, they must all be associated somehow. In Visual Studio, for example, you add your files to a project and the compiler builds them all together. It sounds like you're not building all of the files.
did you figure out your problem with your code? I think I am in your class. my issue thus far is that the code compiles, but for some reason it does not update the iteration through the letters...
IE it keeps asking if the letter a is in the word, and not proceeding to b and so forth