Skip to content

Instantly share code, notes, and snippets.

@furball514
Created November 12, 2017 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furball514/56812afac02f2f7e02a728ab33b90a0b to your computer and use it in GitHub Desktop.
Save furball514/56812afac02f2f7e02a728ab33b90a0b to your computer and use it in GitHub Desktop.
hangman unfinished
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
const string words[7] = {
"China", "Russia", "Switzerland", "Liechtenstein",
"Thailand", "Japan", "Canada",
};
const int lives = 5;
int generateRandomNumber() {
srand((int)time(0));
return (rand() % 6);
}
string returnString(int num) {
string str = "";
for (int i = 0; i < num; i++) {
str += '*';
}
return str;
}
void checkGuess(string input, string chosenWord, string wordToGuess) {
cout << chosenWord.compare(input) << endl;
}
void startGame() {
const string chosenWord = words[generateRandomNumber()];
string wordToGuess = chosenWord[0] + returnString(chosenWord.length() - 1);
cout << " Starting game... " << endl
<< " Your word is " << chosenWord.length() << " letters long. " << endl
<< " This is your word: " << endl
<< wordToGuess << endl
<< " You have 5 tries. Good luck! " << endl
<< " Enter a letter: ";
string input;
getline(cin, input);
checkGuess(input, chosenWord, wordToGuess);
}
int main() {
cout << " Hangman - A Command Line Game " << endl
<< " Your topic - Countries " << endl;
startGame();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment