I made this hangman program and everything works except I have been trying to put a variable named count which adds one everytime an incorrect letter is guessed and after six incorrect guesses the program quits, but i dont know where to put it so that it will work any help would be appreiciated here is my code:
Code:#include<iostream.h> #include<console.h> #include<string.h> int main() { int count=0; int wrong; string secret; char answer; string answer2; string cover; cout<<"Enter word: "<<endl; //User enters word to be guessed cin>>secret; cover=secret; answer2=secret; clrscr();// clears screen for(int i=0; i<secret.length(); i++)//prints dashs to show length of word { cover[i]='-'; cout<<cover[i]; } cout<<endl; do{ cout<<"Enter your guess($ to guess the whole word and * to quit): "<<endl; cin>>answer; if(answer=='$') // Allows you to guess the whole word { cout<<"Enter your letter guess for the whole word: "; cin>>answer2; if(secret==answer2) // checks if word entered is right { cout<<"You are right!"<<endl; answer='*'; } else { cout<<"incorret, guess again"<<endl; } } else { for(int j=0; j<secret.length(); j++) //changes dashs to correct letters guessed { if(secret[j]==answer) { cover[j]=answer; wrong=true; } cout<<cover[j]; } cout<<endl; if(wrong!=true) count++; if(count==1) cout<<"O"; else if(count==2) cout<<" O "<<endl<<" | "; else if(count==3) cout<<" O "<<endl<<" /| "; else if(count==4) cout<<" O "<<endl<<" /|\ "; else if(count==5) cout<<" O "<<endl<<" /|\\ "<<endl<<" / "; else if(count==6) { cout<<" O "<<endl<<" /|\\ "<<endl<<" / \\ "; cout<<"You've lost!"; answer='*'; } cout<<" "<<count; cout<<endl; if(secret==cover) //When all letters guessed program ends { cout<<"You guessed it!"; answer='*'; } } }while(answer!='*'); return(0); }