hey, kind of new to c++ started working with functions and am trying to write program using them

trying to make hangman game using functions, with my following code i am getting this error message
[linked error] undefined reference to 'askGuess()'
id returned 1 exit status
[build error] [ number5.exe] error 1

could please tell me what this error message means. i put my code so maybe can better identify why it is.

thanks for help in advance

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cctype>

using namespace std;

char askGuess();
int main()
    //initial setup
    const int MAX_WRONG = 8;// constant variable

    vector<string> words;//creating words that will be in gmae for user to guess

    srand(static_cast<unsigned int>(time(0)));//help create random order
    random_shuffle(words.begin(), words.end());// randamizies list
    const string THE_WORD = words[0];// selects word from randomized list// moved all 4 under this to function
    int wrong = 0;// starts number of guesses to 0
    string soFar (THE_WORD.size(), '-');//how much word guessed so far
    string used = "";//letters guessed already

    cout << "Welcome to Hangman. Good Luck!!!" << endl;

    while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
          cout << "\n\n You have "  << (MAX_WRONG - wrong) << " incorrect guesses left\n";
          cout << " You have used the following letters: \n" << used << endl;
          cout << " So far, the word is " << soFar << endl;


          if (wrong == MAX_WRONG)
                    cout << "it has taken you to many guess. YOU LOSE! ";
               cout << " you got it. the words was " << THE_WORD << " YOU WIN!\n";

return 0;

char askGuess ( string usedLetterStr)
  char guess;
  cout << " enter your guess \n";
  cout << guess;
  guess = toupper(guess);//changes letter entered to uppercase b/c word is in upper case in vector
  string used = "";
  while (used.find(guess) != string::npos)
        cout << "\nYou have already guess " << guess << endl;
        cout << " Enter your guess: ";
        cin >> guess;
        guess = toupper(guess);// again just changes to uppercase

  if ( THE_WORD.find(guess) != string::npos)
       cout << "That's right " << guess << " is in the word." << endl;
       for ( unsigned int i = 0; i < THE_WORD.length(); i++)
           if (THE_WORD[i] == guess)
                           soFar[i] = guess;

       cout << "sorry " << guess << " is not in the word\n";

Edited by gl7: n/a

5 Years
Discussion Span
Last Post by gl7

On line 10 you say that you have a function named askGuess that takes no arguments and returns a char. On line 55 you define a function named askGuess that takes a string argument and returns a char.

Because these functions have different argument types, the compiler assumes that they are different functions.

On line 38, you call askGuess with no arguments. The compiler assumes that you are calling the function that you declared in line 10. That function is not defined anywhere, so your program doesn't link successfully.

Incidentally, while we're at it, the askGuess function that you define starting on line 55 is claimed to return a char, but you don't actually have a return statement anywhere in it. Therefore, if you were to call it, it would return garbage.


alrite so my code is and my connection/ using of functions is all messed up. i think i get it
thanks alot arkoenig

i just never got that error message, and didnt now to to start to fixing it but now know where to start, again thanks

Edited by gl7: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.