1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string answer;
string empty_list;
int i;
string letter;
bool found;
//srand(time(0));
srand(static_cast<unsigned int>(time(nullptr)));
const string wordList[19] =
{
"sanctuary",
"sting",
"cabinet",
"terrify",
"harvest",
"departure",
"collar",
"profession",
"muscle",
"feeling",
"process",
"recommend",
"deter",
"bald",
"date",
"shadow",
"particle",
"build",
"tired"
};
string word = wordList[rand() % 4];
i = 0;
empty_list = "h";
int l = word.length();
while (l > 0)
{
empty_list[i] = '_';
i = i + 1;
l = l - 1;
}
cout << empty_list << endl;
int count = 0;
int lives = 7;
int size = word.size();
while (count < size && lives > 0)
;
{
cout << "guess a letter" << endl;
cin >> letter;
found = false;
if (word.find(letter) == std::string::npos)
{
found = true;
cout << "that letter is correct :O" << endl;
count = count + 1; // <--- count++;
}
else
{
cout << "that letter is incorrect :(" << endl;
lives = lives - 1; // <--- lives++;
}
}
}
|