i have a computer science project for which i am recreatin the game of hangman as "classmate"
here is my code
the problem is that the correct guess of the name is not shown as "you won"
somebody please run this code and help
it is done in tc++ so watch out for conio.h
#include"iostream.h"
#include"conio.h"
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
char list[][20]={"aakriti","abhishek","adhitya","aditya","akshat","amrita","anirudh","ashwath","bharath","dhruva","esha","ganesh.sompur","ganesh.nayak","gautham","jagannath","kiran","krithika","niranjan","nitin","nivedita","omkar","prajna","prateek","riddhi","rohan","rushab","sangameshwar","sanjay","santhanam","shashwat","shreyas.s.h","shreyas.v","shruthi.m","shruti.t","siddharth.c","siddharth.kothari","sujith","sumukh","swaraj"};
char pw[6],chtcd[6]="79971",ct,clmt[11]="CLASSMATE";
int cccc=0;
void rules()
{
cout<<"\nHiT rEtUrN tO pRoCeEd...";
getchar();
clrscr();
cout<<"\nThEsE aRe ThE rUlEs:\n\n";
cout<<"\n\nAt RaNdOm, A nAmE oF a ClAsS xIb StUdEnT wIlL bE sElEcTeD";
cout<<"\n\nYoU hAvE tO gUeSs ThAt PeRsOn'S nAmE iN nInE gUeSsEs";
cout<<"\n\nyEs, OnLy NiNe, NoT mOrE, nOt LeSs";
cout<<"\n\n\nhAvE fUn, AnD rEmEmBeR: nO fUnNy StUfF\n\n";
}
void play()
{
cout<<"\nHiT rEtUrN tO pRoCeEd...";
getchar();
clrscr();
unsigned int n=39;
char gname[20];
randomize();
n=random(39);
strcpy(gname,list[n]);
int j,chk=0;
char guess,yn;
unsigned int number,cchk=0;
if(cccc==1)
{
do
{
cout<<"\ndO yOu WaNnA cHeAt???[ {y/Y} / {n/N} ]:\t";
cin>>yn;
if(yn=='y' || yn=='Y')
{ cchk=1;
do
{
cout<<"\nsO yOu WaNnA cHeAt\neNtEr A dIgIt(NoT 0 oR 1): ";
cin>>number;
if(number>9 || number == 0 || number == 1)
cout<<"\nfOlLoW tHe InStRuCtIoNs PlEaSe\n";
}while(number>9 || number == 0 || number == 1);
}
if(yn!='y'&& yn!='n' && yn!='Y' && yn!='N')
cout<<"\nsAy OnLy [ {y/Y} / {n/N} ]";
}while(yn!='y'&& yn!='n' && yn!='Y' && yn!='N');
}
cout<<"\nHiT rEtUrN tO pRoCeEd...";
getchar();
clrscr();
for(int i=0;gname[i]!='\0';i++)
{
chk=j=0;
while(j<12&&gname[j]!='\0')
{
if(gname[i]=='.' || ( cchk==1 && i%number==0) )
chk=1;
j++;
}
gotoxy((i+2),5);
if(chk==1)
cout<<gname[i];
else
cout<<'!';
}
int t=0,cr=(strlen(gname)),c=0;
int l;
while(t<9 || c==cr)
{
cout<<"\neNtEr GuEsS ";
cin>>guess;
l=0;
int h=0;
for(int i=0;i<=cr;i++)
{
for(;h<=cr;h++)
{
gotoxy((h+2),5);
if(guess==gname[h])
{
cout<<guess;
c++;
h++;
l=1;
break;
}
}
if(l==0)
{
gotoxy(t+2,10);
cout<<clmt[t];t++;l=0;break;
}
}
}
if(t==9)
{
clrscr();
cout<<"\nyOu LoSt!\ntHe CoRrEcT nAmE iS ";
puts(gname);
}
else
{
clrscr();
cout<<"\nyOu WoN!";
}
getch();
}
void main()
{
int ch;
do
{
cout<<"\nHiT rEtUrN tO pRoCeEd...";
getchar();
clrscr();
cout<<"\n\t\t\tWeLcOmE tO ClAsSmAtE\n\n";
cout<<"\n1.RuLeS\n\n2.PlAy\n\n3.eNtEr ChEaT cOdE\n\n4.cHeAt WiThOuT a CoDe\n\n5.ExIt :-(\n\n\tEnter choice:\t";
cin>>ch;
switch(ch)
{
case 1: rules();break;
case 2:play();break;
case 3: cout<<"\neNtEr ChEaT cOdE: ";
gets(pw);
if( strcmp( pw , chtcd ) == 0 )
{
cccc=1;
cout<<"\nyOu GoT iT :-D :-D :-D\n";
}
break;
case 4: cout<<"\nHiT rEtUrN tO pRoCeEd...";
getchar();
clrscr();
cout<<"\ncHeAtErS nEvEr PrOsPeR :-P :-P :-P";
abort();
case 5:break;
default:cout<<"\nErRoR 420 (mIsSiNg ChOiCe NuMbEr)\nPlEaSe TrY aGaIn\n";break;
}
}while(ch!=5);
cout<<"\nThAnK yOu FoR pLaYiNg ClAsSmAtE\n\nMaDe By: AnIrUdH r., XiB";
getchar();
cout<<"\nThAnKs";
getchar();
cout<<"\nThAnKs A lOt";
getchar();
cout<<"\nThAnKs A gOoGoL";
getchar();
cout<<"\nThAnKs\nNo ReAlLy, I sTiLl MeAn It";
cout<<"\nHiT rEtUrN tO pRoCeEd...";
getchar();
cout<<"\nHiT rEtUrN tO pRoCeEd...";
getchar();
cout<<"\nHiT rEtUrN tO pRoCeEd...";
getchar();
abort();
}