Originally Posted by
gunghomiller
I changed it to
and it displays "The number of times John was used is:0" three times. Which it used three times however i dont want the sentence to be displayed three times i want the number three to be displayed. I appreciate all the help immensly gents but the terms I do not know all of them.
So you need two changes. Firstly, somewhere you want to change the value of 'J' .
Secondly, you need to put your cout<< statement somewhere that it only prints once.
Have a look at the structure of the program, based on what you know about your output..
Code:
//Everything up here is executed once
while (position != string::npos)
{
//Everything between these curly braces is executed per each occurrance of "John"
position = quote.find("John", position +1);
cout << "The number of times John was used is: " << j;
}
//Everything down here is executed once