#include <iostream> #include <string> using namespace std; #define ll long long int main() { srand(time(0)); const int SIZE = 10; string words[SIZE] = { "skinny","skinny","three","arrange", "discussion", "squeeze" ,"flowers","credit","matter","visit"}; int random = rand() % SIZE; string s = words[random]; string astrid_word(""); astrid_word = s; for (int i = 0; i < astrid_word.length(); i++) { astrid_word[i] = '*'; } char guess; int tries = 1; bool youWin = false; int miss = 0; while ( tries <= 20) { int flag = 0; cout << tries<<" enter your guess " << astrid_word<<" "; cin >> guess; for (int i = 0; i < astrid_word.length(); i++) { if (s.at(i) == guess) { if (s.at(i) == astrid_word.at(i)) { cout <<" "<< guess << " is already in the word\n"; } else { astrid_word.at(i) = guess; flag = 1; } } } if (flag == 0) miss++; if (astrid_word == s) { youWin = true; cout << "the word is " << astrid_word<<endl; break; } tries++; } if (youWin == true) { cout << " -------------------------------- \n"; cout << "| |\n"; cout << "| |\n"; cout << "| (:CONGRATULATIONS YOU WIN(: |\n"; cout << "| |\n"; cout << "| |\n"; cout << " -------------------------------- \n"; cout << "you tried " << tries << " times \n"; cout << "you miss " << miss << " time\n"; } else { cout << "the word is " << s << "): you loose ):"; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter