pattern matching

This is a discussion on pattern matching within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by gunghomiller I changed it to and it displays "The number of times John was used is:0" three ...

  1. #16
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by gunghomiller View Post
    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

  2. #17
    Registered User
    Join Date
    Jul 2007
    Posts
    35
    Hey I got it I just used an if statement and then put a counter in there! Gosh I feel like dumb!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 08:54 PM
  2. filename pattern matching
    By dwks in forum C Programming
    Replies: 11
    Last Post: 07-13-2005, 11:23 AM
  3. Pattern matching
    By GSLR in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-06-2003, 07:17 AM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 07:27 PM
  5. pattern matching
    By ahahplz in forum C Programming
    Replies: 5
    Last Post: 02-07-2003, 07:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21