-
Hangman program
I have to create a program that asks the user for a word clears the screen then lets the user guess the letters or the whole word so far i have it so that is clears the screen after the word is entered and if you want to guess the whole word you can, the problem is I dont know what to do with guessing single letters
this is what i have so far:
Code:
#include<iostream.h>
#include<console.h>
#include<string.h>
int main()
{
char secret[100];
char answer;
char answer2[100];
cout<<"Enter word: "<<endl;
cin>>secret;
clrscr();
for(int i=0; i<secret.length(); i++)
{
cout<<"-";
}
cout<<endl;
do{
cout<<"Enter your guess($ to guess the whole word and * to quit): "<<endl;
cin>>answer;
if(answer=='$')
{
cout<<"Enter your guess for the whole word: ";
cin>>answer2;
if(strcmp(secret, answer2))
cout<<"incorret, guess again"<<endl;
else
cout<<"You are right!";
}
}while(answer!='*');
return(0);
}
I need to make the output something like
----
-a--
ca--
etc.
I also wanted to use secret.length(); to print the intial dashs of how long the word was but I cant get it to work
Any help is apprieciated
thank you
-
char isn't a class and doesn't have a length() member function
You probably want string. Include <string> and use the standard namespace.
And instead of using strcmp, just use == (overloaded operator found in the string class)
To find if it's in your string... just go from position 0 to the end of the string is see if your char matches any place... if it does... use some sort of gotoxy() to place that char on the screen
You can do it :D