// Hangman Redo Program
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
//Functions
void welcome();
void instructions();
int game(string sofar, const string THE_WORD, int MAX_WRONG, int wrong, string used);
// Types and Arrays
string choice;
string inst;
const int MAX_WRONG = 8;
int main()
{
vector<string>words;
words.push_back("ALPHABET");
words.push_back("SKUNK");
words.push_back("ANIMALS");
words.push_back("TABLE");
words.push_back("CASE");
words.push_back("MONITOR");
words.push_back("TELEVISION");
words.push_back("SOAP");
words.push_back("BERUIT");
words.push_back("WRAP");
words.push_back("CHAIR");
words.push_back("CHARTER");
words.push_back("COMPUTER");
words.push_back("SHARPENER");
words.push_back("PENCIL");
words.push_back("WALLS");
words.push_back("LUNG");
words.push_back("NOTHING");
words.push_back("HAIR");
words.push_back("SECRUITY");
words.push_back("NIXON");
words.push_back("DESTROY");
words.push_back("OUTLET");
srand(static_cast<unsigned int>(time(0)));
random_shuffle(words.begin(), words.end());
const string THE_WORD = words[0];
int wrong = 0;
string sofar (THE_WORD.size(), '-');
string used = "";
welcome();
return 0;
}
void welcome()
{
for (int f = 0; f < 11; f++) // formating
{
cout << endl;
}
cout << "\t\tWelcome to Hangman 2.0 By Khoanyneosr!";
for (int i = 0; i < 14; i++) // for statement to create space under title
{
cout << endl;
}
system("pause"); // creates a pause;
system("cls"); // clears the console screen
cout << endl << "Would you like to see the instructions?\n\n";
cout << endl << "Yes - Y" << endl;
cout << endl << "No - N\n\n- ";
cin >> choice;
transform(choice.begin(), choice.end(), choice.begin(), toupper); // toupper algorithm
cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
bool done = false;
while (done == false)
{
if (choice == "Y")
{
instructions();
done = true;
break;
}
else if (choice == "N")
{
game();
done = true;
break;
}
else
{
cout << endl << "Invalid input.\n- ";
cin.clear();
cin >> choice;
transform(choice.begin(), choice.end(), choice.begin(), toupper); // toupper algorithm
cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' ); // limit cin to one character.
}
};
}
void instructions()
{
system("cls");
cout << endl << "\t\tINSTRUCTIONS: ";
cout << endl << "1 - You'll be presented with some blank spaces.\n";
cout << endl << "2 - Your job is to guess which letters go in the spaces.\n";
cout << endl << "3 - If you guess the right letter, then you'll be given 1 point.\n";
cout << endl << "4 - If you guess the wrong letter 1 point will be deducted.\n";
cout << endl << "5 - If you think that you know the word, you can guess the word\n\n\tby typing \"Guess\" at any time.\n\n";
cout << endl << "Good Luck!" << endl << endl;
system("pause");
game();
}
int game(string sofar, const string THE_WORD, int MAX_WRONG, int wrong, string used)
{
system("cls");
while ((wrong < MAX_WRONG) && (sofar != THE_WORD))
{
cout << "\n\nYou have " << (MAX_WRONG - wrong);
cout << " incorrect guesses left.\n";
cout << "\nSo far, the word is:\n" << sofar << endl;
char guess;
cout << "\n\nEnter a guess: ";
cin >> guess;
cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' ); // limit cin to one character.
guess = toupper(guess);
while (used.find(guess) != string::npos)
{
cout << "\nYou've already guessed " << guess << endl;
cout << "Enter your guess: ";
cin >> guess;
guess = toupper(guess);
}
used += guess;
if (THE_WORD.find(guess) != string::npos)
{
cout << "That's right! " << guess << " is in the word.\n";
// update the newly guessed letter into the word
for (unsigned int i = 0; i < THE_WORD.length(); ++i)
{
if (THE_WORD[i] == guess)
{
sofar[i] = guess;
}
}
}
else
{
cout << "Sorry, " << guess << " isn't in the word.\n";
++wrong;
}
}
// shut down
if (wrong == MAX_WRONG)
{
cout << "\nYou've been hanged!";
}
else
{
cout << "\nThe word was " << THE_WORD << endl;
}
return 1;
}
So that's my code as of now. I originally had it as void and returning no values but the compiler said...
Error 1 error C2660: 'game' : function does not take 0 arguments c:\users\konnor\documents\visual studio 2010\projects\hangman_redo\hangman_redo\hangman_redo.cpp 97 1 hangman_redo
so.... I changed it to int and returning 1. The same thing happened. Im not sure what to do from here so... please help =)