- #1
adrumheiser
- 2
- 0
Hi all, I am new to c++ and need help with my homework. I have tried many times and somehow cannot get it right. My following code works for 'darn' but when tested with "Dang, that was scary!," prints censored also. Any hints?
Print "Censored" if userInput contains the word "darn", else print userInput. End with newline.
#include <iostream>
#include <string>
using namespace std;
int main() {
string userInput;
userInput = "That darn cat.";
if (userInput.find("darn")) {
cout << "Censored" << endl;
}
else {
cout << userInput << endl;
}
return 0;
}
Print "Censored" if userInput contains the word "darn", else print userInput. End with newline.
#include <iostream>
#include <string>
using namespace std;
int main() {
string userInput;
userInput = "That darn cat.";
if (userInput.find("darn")) {
cout << "Censored" << endl;
}
else {
cout << userInput << endl;
}
return 0;
}