166k views
2 votes
Rint "Censored" if userInput contains the word "darn", else print userInput. End with newline.

#include
#include
using namespace std;

int main() {
string userInput;

userInput = "That darn cat.";

/* Your solution goes here */

return 0;
}

User Maxxx
by
5.4k points

1 Answer

4 votes

If you're coding with C++ then the solution would be:

if (userInput.find("darn") != -1) {

cout << "Censored" << endl;

}

else{

cout << userInput << endl;

}

Keep in mind that this will reject any input with the word "darn" in the sentence. This will not filter the word darn if the capitalization is in different formats like "Darn, dArn, daRn, darN, DARN".

User Joakim Elofsson
by
5.1k points