It is a simple project just to provide a Hang Man game concept.In this project I haven’t draw a man for a wrong choice so,try to draw a simple man by using “|” pattern in your project which make your project better .
Here is the source code ,copy and compile it in Code::blocks gcc compiler.
PROGRAM:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <cstring>
using namespace std;
inline void type_of_word(char f);
int main()
{ char c,h,ch,ch1,ch2;
char word[25];
char word2[25];
int l,i,ng,n,k,x;
do{
do{
c=' ';
cout<<"ntt *********** HANGMAN IN C++ ***********nn";
cout<<"(E) Enter a wordnn(C) Computer chooses wordnn(A)" ;
cout<<"Add new word to listnn(Q) QuitnnnEnter your choice (E - C - Q): ";
cin>>ch2;
}while (ch2!='C' && ch2!='c' && ch2!='E' && ch2!= 'e' &&
ch2!='Q' && ch2!= 'q'&& ch2!='A' && ch2!= 'a');
if (ch2 == 'Q' || ch2=='q') exit (0);
if (ch2 == 'C' || ch2=='c')
{
ifstream fin("hangword.txt");
if(!fin) {
cout<<"File missing, aborting.nnYou are missing a file of name" ;
cout<<"**hangword.txt**nnLocate it, then place it next to the" ;
"program file.nn"; system("pause"); return 0;}
for (i=0;!fin.eof();i++) fin.getline(word,25);
fin.close();
do {
x=rand();
}while(x>i || x<0);
ifstream finn("hangword.txt");
for (i=0;!finn.eof();i++)
{finn>>c; finn.getline(word,25); if (x==i) break;}
finn.close();
}
if (ch2 == 'A' || ch2=='a')
{
ofstream fout("hangword.txt",ios::app);
if(!fout) {//clrscr();
cout<<"File missing, aborting.nnYou are missing a file of name"
" **hangword.txt**nnLocate it, then place it next to the program"
" file.nn"; system("pause"); return 0;}
cin.get();
cout<<"Choose the topic of your wordnn(M) Movienn(A) Animalnn(P)"
" Sportnn(S) SongnnEnter your choice (A-P-S-M) : ";
cin>>h;
cin.get();
//clrscr();
cout<<"nnThe word should not exceed 25 lettersnnEnter the word : ";
cin.getline(word,25);
fout<<h<<word<<endl;
fout.close();
}
if (ch2 == 'E' || ch2=='e')
{// clrscr();
cin.get();
cout<<"ttt Type the word : ";
cin.getline (word, 25);
}
if (ch2 == 'E' || ch2=='e' || ch2 == 'C' || ch2=='c')
{
l=strlen(word);
char choosen[25]="