From 940cbd960527efa1f0802b191a5a13ee04f5f4ce Mon Sep 17 00:00:00 2001 From: Chetanya Chopra Date: Sun, 17 Jul 2016 21:13:27 -0700 Subject: [PATCH] Add files via upload SEARCH for WORD in a paragraph... --- searching.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 searching.cpp diff --git a/searching.cpp b/searching.cpp new file mode 100644 index 000000000..ecf05e800 --- /dev/null +++ b/searching.cpp @@ -0,0 +1,45 @@ + #include +#include + +using namespace std; +char paragraph; + + +int main() +{ + string paragraph; + cout << "Please enter your paragraph:"; + getline (cin,paragraph); + cout << "Hello, your paragraph is " << paragraph << "!\n"; + string paragraph1 = paragraph; + //string sentence = paragraph + " " +paragraph + " " + paragraph; + //cout << sentence << endl; + cout << "The size of your paragraph = " << paragraph.size() << " characters. \n\n"; + string word; + cout << "Please enter the word you are searching for:"; + getline (cin,word); + + cout << "Hello, your word is " << word << "!\n"; + + + +bool wordsearch = true; + do { + if (paragraph.find(word) == string::npos) + cout << "" << word << " does not exist in the sentence" << endl; + + cout << "The word " << word << " is now found at location " << paragraph.find(word) << endl << endl; + + + + if (paragraph.empty()) + { + cout << "\nThe sentence is empty" << endl; + } + else + cout << "\nThe sentence is not empty" << endl; + + system ("pause"); + + }while (wordsearch = true); +}