Hello,
Here's the details:
User inputs sentence
Program checks sentence for 3 magic words ("chicken", "egg", "rooster")
Program keeps count of every magic word found and displays results
Here's my code:
#include<iostream>
#include<string>
using namespace std;
const string chicken( "chicken" );
const string egg( "egg" );
const string rooster( "rooster" );
const string quit( "FINISHED" );
int main ()
{
string inputSentence;
int w1Found, w2Found, w3Found;
cout << "Type a sentence" << endl;
cin >> inputSentence;
do {
if ( inputSentence == chicken )
{
w1Found++;
} else if ( inputSentence == egg )
{
w2Found++;
} else if ( inputSentence == rooster )
{
w3Found++;
}
cin >> inputSentence;
} while ( inputSentence != quit );
cout << "\"" << chicken << "\" strings found: " << word1found << endl;
cout << "\"" << egg << "\" strings found: " << word2found << endl;
cout << "\"" << rooster << "\" strings found: " << word3found << endl;
}
Problem with this code is that it requires EVERY sentence typed to end with "FINISHED" for it to work and know when to stop counting. I need to figure out a better way. Like:
hello blah blah chicken chicken blah egg
"chicken" found: 2
"egg" found: 1
"rooster" found: 0
But now I have to do hello blah blah chicken chicken blah egg FINISHED for it to work