So you need two changes. Firstly, somewhere you want to change the value of 'J' .
Originally Posted by gunghomiller
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..
//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
Hey I got it I just used an if statement and then put a counter in there! Gosh I feel like dumb!