From 2a7243e58a1d00f106d81d64e7bd8eb8dc8c000a Mon Sep 17 00:00:00 2001 From: Saumay-Agrawal Date: Fri, 10 Feb 2017 21:57:32 +0530 Subject: [PATCH] update searching.cpp * added #include - it was causing compile time error * made code and output more readable * removed unused variables * repositions some conditions in logical manner --- searching.cpp | 58 +++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/searching.cpp b/searching.cpp index 53ee830d6..eab40e4e8 100644 --- a/searching.cpp +++ b/searching.cpp @@ -1,45 +1,39 @@ - #include -#include +#include +#include +#include using namespace std; char paragraph; - int main() { string paragraph; - cout << "Please enter your paragraph:"; + cout << "Please enter your paragraph: \n"; 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 << "\nHello, your paragraph is:\n " << paragraph << "!\n"; + cout << "\nThe size of your paragraph = " << paragraph.size() << " characters. \n\n"; - 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()) + if (paragraph.empty()) { - cout << "\nThe sentence is empty" << endl; + cout << "\nThe paragraph is empty" << endl; } else - cout << "\nThe sentence is not empty" << endl; + { + while (true) { + string word; + cout << "Please enter the word you are searching for: "; + getline (cin,word); + cout << "Hello, your word is " << word << "!\n"; + if (paragraph.find(word) == string::npos) + { + cout << word << " does not exist in the sentence" << endl; + } + else + { + cout << "The word " << word << " is now found at location " << paragraph.find(word) << endl << endl; + } + system("pause"); + } - system ("pause"); - - }while (wordsearch = true); -} \ No newline at end of file + } +}