Only once help

I am trying to make this program, where the user will try to guess what my name is and it will check. If the user guesses it correct, it should only print: "You guessed Max Zaloznyi". And I have another cout like that, if they guess wrong. When you guess correct, it prints the same cout twice, which I don't want. How can I fix this? Hopefully this makes sense.

Code:

<-------------------------------------------------------------------------------
void cStringDemo() {
char myName[] = "Max Zaloznyi";
char inputName[50];

cout << "Guess my full name (first last): ";
cin.get(inputName, 50);

if (strcmp(myName, inputName) == 0)
cout << "\nYou guessed " << myName << endl;
else
cout << "\nNice try, but incorrect " << endl;

// Manipulate user input name
cout << "\nYou guessed " << inputName << endl;
cout << "Without vowels, that's " << removeVowel(inputName) << endl;
cout << "\nAnd in less civilized times, it would be " << strcat(inputName, " the Barbarian") << endl;

}
<-------------------------------------------------------------------------------
I think you want the block of statements after the else statement to be a part of the first if case.

Unless you want them to execute regardless then you can either add another if statement for the second cout You Guessed statement or erase the first cout You Guessed statement under the if condition and change the if condition to check NOT strcmp instead of strcmp.
Last edited on
Topic archived. No new replies allowed.