CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2012
    Posts
    3

    Reading Input Real-Time

    I'm trying to code a program to read the user's input and have it:

    -count vowels
    -stop counting vowels after '.' or '?' (ie. abcdjwef is 1 a, 1 e; while fje.fwdfeiii is just 1 e)
    -closes when ENTER is pressed after a '.' or '?' is found (ie. closes after 'abacds. ENTER' as well as 'as.fefsdf ENTER')
    -display the number of vowels

    Is there any way to do this with only 'cin >> userInput' and a while loop checking for punctuation?

  2. #2
    Join Date
    Sep 2007
    Location
    Calcutta, India
    Posts
    95

    Re: Reading Input Real-Time

    Code:
    char userInput = NULL; //userInput initialized
    
    /*******************************************************
    while userInput not equal to '.', '?', or carriage return and newline or just 
    carriage return, depending on your system
    ********************************************************/
    while (!(userinput == '.' || userinput == '?' ||userinput == '\r\n'))
    {
        cin >> userInput
        
        /* The vowel calculation code
        *  goes here
        */
    }
    
    /*
    * The if/elseif/else condition to test userInput for one of the delimiting
    * characters goes here
    */
    if(userinput == '.' || userinput == '?' )
        //stop counting vowels, that's all
    else
    //userInput is equal to carriage return, this part may get dicy, apply your intelligence
        //do cleanup work and output of the program
        exit(0);
    
    exit(1);
    The exit(0) indicates a succesful completion of the program and exit(1) indicates failure. Feel free to use them at free will, but carefully.

    If this reply works for you, please mark this thread as [RESOLVED] from the control panel.

    Thanks & Regards
    Indrajit
    Last edited by indrajit_p1; October 1st, 2012 at 01:22 AM. Reason: incomplete code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured