Created
November 12, 2017 08:57
-
-
Save furball514/56812afac02f2f7e02a728ab33b90a0b to your computer and use it in GitHub Desktop.
hangman unfinished
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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