I am making a game commonly know as the Hangman using C++.
Now i am trying to add a man in it like this
0
\|/
|
/ \
no the problem i am facing is that i am using a check that if a function returns the value 0 "return 0" it means the guess is wrong and it will not update the man but if it returns any value there will be a function called which will update the man.
i just wanna know that how i am going to use the check
the kind of thing that i am trying to use is, in general words "if(function returns a value)
then update the man"
int main()
{
return match;
}
how are we going to use it in check that if int main is returning 'match' in the check
plz help !!!
Hangman starts with no man, correct? When you guess correctly, nothing is added. When you guess incorrectly, a part of the man is added. If you guess incorrectly too many times the entire man is hanged, game over. in pseudo:
if guess wrong, add part of man, move on to next guess
if guess right, move on to next guess
if man is complete, lose
if word has been completed, win
You can simply use the NOT operator on the function call, so if the return value is 0 (false), it will evaluate true, and the code will be executed. In this manner:
1 2 3 4 5 6 7 8 9 10 11 12 13
int functionX() //*The funciton that will return the value 0, amongst other values.
{
int match=0;
return match;
}
int main()
{
if (!functionX()) //*execute and test the function that returns such value
{
//*Do your wrong answer stuff
}
}
Note that "match" will only exist inside the function, thats not what you are going to test!