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
    words.push_back("HANGMAN");
    words.push_back("DIFFICULT");
    words.push_back("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;


          askGuess();

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

cin.get();
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;
           }
       }

  }
  else
  {
       cout << "sorry " << guess << " is not in the word\n";
       ++wrong;
  }
}

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.