+ 3
It's because of how you set up your IF statement. || creates an expression on both sides, so 'b' by itself is true, thus the IF expression is true. This is a good case of using a switch or something like that. Give me a moment and I'll type up some code for you.
21st Nov 2017, 6:37 PM
AgentSmith
+ 3
This is how you could use a switch statement in that situation, based solely upon your code. However, if you're doing hangman, then you'd want to do a lot of things differently. For example, maybe have it automatically generate a word at the beginning, store each letter from the word in an array, and then using a loop, check user input against the values in the array. Just as a quick solution on the fly. Anyways, best of luck to you! Hope this helps. https://code.sololearn.com/cXwdHOtya3Kk/#cpp #include <iostream> #include <string> using namespace std; int main() { char aLetter; cout<<"HANGMAN \n\n"; cout<<"...... .. ... \n\n"; cout<<"Please insert a character. \n\n"; cin>>aLetter; cout<<aLetter<<endl; switch(aLetter){ case 'c': case 'd': case 'f': case 'i': case 'n': case 'o': case 's': case 'g': case 'u': cout<<"Yes! Please insert another character. \n\n"; break; default: cout<<"No. Please insert another character. \n\n"; break; } return 0; }
21st Nov 2017, 6:42 PM
AgentSmith
+ 2
You're welcome! Best of luck to you bro.
21st Nov 2017, 9:04 PM
AgentSmith