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

    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
    Calcutta, India

    Re: Reading Input Real-Time

    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
    //userInput is equal to carriage return, this part may get dicy, apply your intelligence
        //do cleanup work and output of the program
    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
    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.