String Counter

This is a discussion on String Counter within the C++ Programming forums, part of the General Programming Boards category; I'm trying to get the program to print the string in one solid line and show how many strings are ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    Exclamation String Counter

    I'm trying to get the program to print the string in one solid line and show how many strings are in the line, its for a study program im working on that will end up comparing the users answer to the stored answer. If anyone has any tips or advice it would be greatly apppreciated.
    Attached Files Attached Files

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    The code, so people don't have to download it themselves:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int nos = 0;   // Number of strings
        int nsc = 0;   // Number  of strings counted
        
        string nui = "";  // Collection of all strings
        ++nsc; // When a string is added to nui add 1 to nsc
        
        string ui;     // Users input
        cout << "Type something" << endl;   
        
        while ((nos > nsc) && ui += nui)    // While nos > nsc and ui has another word to add to the nui
        {                                   // continue checking for new strings in ui if ui += nui it partialy works.
              cin >> ui;                    // Users Input
              ++nos;                        // add +1 to nos for each word input
              ui += nui;                    // add new word to nui
        }
        // Print out the results
        cout << "You typed - " << nui << " - and it had - " << nsc << " - words in it." << endl;
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Vague questions rarely get good answers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Counter
    By ejiroy in forum C Programming
    Replies: 3
    Last Post: 03-01-2011, 09:54 AM
  2. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 03:17 AM
  3. how to find string length without using counter
    By nitinmhetre in forum C Programming
    Replies: 4
    Last Post: 09-03-2007, 07:42 AM
  4. The counter
    By Gordon in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:50 AM
  5. String counter increase thingy problem : )
    By rmullen3 in forum C++ Programming
    Replies: 1
    Last Post: 11-22-2001, 03:47 PM

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