I have been beating my head against this code for a few days now. it throws a:
template argument deduction/substitution failed:
error on lines 119, 124,129, 162. (marked with //ERROR HERE )
i am still a super n00b at coding so any help would be appreciated. THANKS IN ADVANCE!!
/*********************
Hangman v2
The classic game of hangman using multiple functions
(from chaper 5 C++ book)
**************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cctype>
using namespace std;
//GLOBALS!!
string THE_WORD; //secret word player is tryign to guess
string soFar; //word string ei: "G-ESS"
const int MAX_WRONG = 8; // maximum number of incorrect guesses allowed
char guess; //character guessed by player
int wrong; //incorrect guesses
//Functions used (declarations)
string f_soFar();
void f_used();
int main();
vector<string> used_ch; ///used characters
string getWord()
{
vector<string> words; // collection of possible words to guess
words.push_back("GUESS");
words.push_back("HANGMAN");
words.push_back("DIFFICULT");
words.push_back("ENTERPRISE");
words.push_back("GALAXY");
words.push_back("POMEGRANATE");
words.push_back("CONTROLLER");
srand(static_cast<unsigned int>(time(0))); //Seed based on time
random_shuffle(words.begin(), words.end()); //randomly picks from words vector
string secretWord;
secretWord = words[0]; // word to guess
THE_WORD = secretWord;
cout<<"New Secret word has been chosen!!"<<endl;
cout<<THE_WORD<<endl;
return THE_WORD;
}
void check(char guess)
{
cout << "\n\nEnter your guess:\n\n->";
cin >> guess;
guess = toupper(guess); //make uppercase since secret word in uppercase
while (find (used_ch.begin(), used_ch.end(), guess) != used_ch.end())
{
cout << "\nYou've already guessed " << guess << endl;
cout << "Enter another guess: ";
cin >> guess;
guess = toupper(guess);
if (THE_WORD.find(guess) != string::npos)
{
cout << "That's right! " << guess << " is in the word.\n";
// update used_ch to include newly guessed letter
for (unsigned int i = 0; i < THE_WORD.length(); ++i)
{
if (THE_WORD[i] == guess)
{
used_ch.push_back(&guess);
soFar[i] = guess;
cout<<"Guess again!"<<endl;
}
}
}
else
{
cout << "Sorry, " << &guess << " isn't in the word.\n";
++wrong;
cout<<"Try again!"<<endl;
}
}
}
void f_used()
{
for(unsigned int i = 0; i < used_ch.size(); i++)
{
cout<<used_ch[i]<<", ";
}
}
void replay()
{
char choice;
cout<<"Would you like to play again?\nY/N\n\n->";
cin>>choice;
if(choice == 'Y' || choice == 'y')
{
cout<<"OK!!!! Here we go...."<<endl;
used_ch.clear();
main();
}
else if(choice == 'N' || choice == 'n')
{
cout<<"OK, thanks for playing!!";
}
else //ERROR HERE
{
cout<<"Invalid Entry. please try again...";
replay();
}
} //ERROR HERE
int main()
{
// set-up
getWord(); //ERROR HERE //should get word from word()
//cout<<"The word is "<<THE_WORD<<endl; //TESTING PURPOSES!!
while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
{
//STATUS
cout << "\n\nYou have " << (MAX_WRONG - wrong);
cout << " incorrect guesses left.\n";
cout << "\nYou've used the following letters:\n";
f_used();
cout << "\nSo far, the word is:\n" << soFar << endl;
check(guess);
}
// shut down
if (wrong == MAX_WRONG)
{
cout << "\nYou've been hanged!";
replay();
}
else
{
cout << "\nYou guessed it!";
cout << "\nThe word was " << THE_WORD << endl;
replay();
}
} //ERROR HERE