Code
#include <bits/stdc++.h>using namespace Std;int bk[110];string sj (int t) {string ans= ""; for (int i=0;i<t;i++) Ans=ans+char ((rand ()%26) + ' a '); return ans;} Main () {Srand (time (0)); cout<< "Hangman game total of 6 times to guess the opportunity, you can choose the difficulty \ n"; cout<< "easy--5 letters consisting of words \nnormal--8 letters consisting of \nhard--12 letters consisting of a word \nlunatic--26 letters" \ n "; while (1) {int sum; cout<< "The difficulty you choose is \ n Please enter Easy,normal,hard or lunatic\n"; F1:string e; cin>>e; if (e== "easy") sum=5; else if (e== "normal") sum=8; else if (e== "hard") sum=12; else if (e== "lunatic") sum=26; else {cout<< "you entered the illegal option please re-enter!!!" \ n "; Goto F1; } string A=SJ (sum); int num=6; memset (bk,0,sizeof (BK)); cout<<a<<endl; cout<< "Please enter a letter \ n"; while (1) {f2:string T; cin>>t; if (T.size () >1) {Cout<< "Enter more than one letter, please re-enter \ n"; Goto F2; } int f,ff; f=1; ff=0; for (int i=0;i<a.size (); i++) if (A[i]==t[0]) {bk[i]++; if (bk[i]==1) f=0; else ff=1; } int ac=1; for (int i=0;i<a.size (); i++) if (bk[i]==0) {ac=0; Break if (AC) {cout<< "--------------------------------------------\ n"; cout<< "Congratulations on your complete guess!!! You also have the remaining << "<<num<<" >> opportunity \ n "; cout<< "The original word is \ n"; for (int i=0;i<a.size (); i++) {if (bk[i]!=0) cout<<a[i]<< ""; else cout<< "_"; } cout<<endl; cout<< "--------------------------------------------\ n"; Break } if (f) {num--; cout<< "--------------------------------------------\ n"; if (F&&!FF) cout<< "The letter you guessed did not appear in the original word!!! \ n "; else if (FF) cout<< "you guessed the right letter you've guessed!!! \ n "; if (!num) {cout<< "--------------------------------------------\ n"; cout<< "You have failed!!! Hangman has been completed!!! \ n "; cout<< "The original word is \ n"; for (int i=0;i<a.size (); i++) cout<<a[i]<< ""; cout<<endl; cout<< "What you finally guessed is \ n"; for (int i=0;i<a.size (); i++) {if (bk[i]!=0) cout<<a[i]<< ""; else cout<< "_"; } cout<< "\ n"; cout<< "--------------------------------------------\ n"; Break } cout<< "The number of times left is <<" <<num<< ">> times \ n"; cout<< "--------------------------------------------\ n "; cout<< "Please enter a letter \ n"; } else {cout<< "--------------------------------------------\ n"; cout<< "Congratulations you guessed the right letter, the word is \ n"; for (int i=0;i<a.size (); i++) {if (bk[i]!=0) cout<<a[i]<< ""; else cout<< "_"; } cout<<endl<<endl; cout<< "--------------------------------------------\ n"; cout<< "Please enter a letter \ n"; } } }}
Small instance Hangman game