This program is a word guessing game in which user have to enter the letters of the word one by one. There are n chances given to guess its letters where n is the no. of letters in that word. The program will also show the mishits at the end.
The program is...
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<iomanip.h>
#include<dos.h>
void main()
{
clrscr();
char ch,arr1[10],ch1[4];
int i,j=0,k=0,l=0,c=0,r=0,z,p;
char arr[8][12]={"DATE","LIGHT","QUESTION","COURSE","PEN","CENTRAL","NOTEBOOK","COMPUTER"};
randomize();
do
{
clrscr();
cout<<"********************************************************************************";
cout<<setw(40)<<" GUESS GAME\n";
cout<<"********************************************************************************";
cout<<"\n\n"<<setw(40)<<" 1. Play the game";
cout<<"\n"<<setw(31)<<" 2. Exit";
cout<<"\n\n\n Please enter your choice :";
cin>>z;
if(z==1)
{
clrscr();
cout<<"\n Guess the letters of the word one by one(letters are in caps) :\n";
i=random(6);
while(arr[i][j]!='\0')
{
cout<<"*";
arr1[j]='*';
j++;
}
j=0;
while(arr[i][k]!='\0')
{
cout<<"\n";
cin>>ch;
while(arr[i][l]!='\0')
{
if(arr[i][l]==ch)
{
arr1[l]=ch;
cout<<arr1[l];
r++;
c++;
}
else
{
cout<<arr1[l];
}
l++;
}
if(r>1)
{
k=k+r;
r=0;
continue;
}
l=0;
r=0;
k++;
}
c=k-c;
k=0;
cout<<"\n\n Actual Word :";
cout<<arr[i];
cout<<"\n No. of mishits :"<<c;
c=0;
cout<<"\n\n Press any key to continue";
getch();
if(kbhit())
{
continue;
}
}
else if(z==2)
{
exit(0);
}
else
{
cout<<"\n\n\a Invalid Character !!!!";
cout<<"\nPlease enter a valid character.";
z=4;
delay(2500);
}
}while(z==1||z==2||z==4);
getch();
}