#include <iostream>
#include <string>
using namespace std;
int main()
{
string str, str1; // Strings for console input.
int num = 0; // The number of words "the" in the line.
cout << "Please enter a line of text: " ;
char c=' '; // Symbol for input correction.
while((cin.peek()!='\n')&&(c!='\n')) // Checking the end of the line.
{
while(c==' ' || c=='\t') // Do not enter spaces and tabs.
{
c=cin.get();
}
if (c!='\n') // If not the end of the line,
{ // then enter the printed characters.
str.clear();
str+=c;
if(cin.peek()!='\n')
{
cin>>str1;
str+=str1;
} // We're forming a word.
c=' ';
//cout<<str<<" "; Can be turned on to control input.
if(str=="the") num++; // Checking the word.
}
}
cout<<endl<<"The number of times the ppears is "<<endl<<num<<endl;
return 0;
}
Comments
Leave a comment