CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Nov 2010
    Posts
    81

    Re: Counting characters help

    By all means, if you have a better way, let me know!! It's not required for our class, but I like to throw everything in there to make my final programs appear more... real. I wrote it a few months ago with a lot less knowledge, and I'm sure I could tweak it a little, but that takes time, which I don't have. What I mean is when I run my program and answer the first question with 'y', it does this:

    Would you like to run this program (y/n)?: y
    There were 0 vowels and 0 consonants in the string.
    There were 0 total characters in the string.
    Would you like to run this program again (y/n)?:
    Press any key to continue...

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Counting characters help

    Quote Originally Posted by LogicWavelength View Post
    By all means, if you have a better way, let me know!! It's not required for our class, but I like to throw everything in there to make my final programs appear more... real. I wrote it a few months ago with a lot less knowledge, and I'm sure I could tweak it a little, but that takes time, which I don't have. What I mean is when I run my program and answer the first question with 'y', it does this:
    So does this mean you are finished with your issue with looping to find out whether a character is a vowel or not?

    Regards,

    Paul McKenzie

  3. #18
    Join Date
    Nov 2010
    Posts
    81

    Re: Counting characters help

    Well, yes Paul. I am handing in that version I posted last, with two nearly identical functions. However, I was hoping this thread would stay alive long enough for you guys to help me learn to do it your way - I just needed to meet my class deadline and that version is good enough - probably better than what anybody else will hand in.

    I will continue my questions with the while loop for re-running the program in a new thread, to keep the two issues separate - if that's what the forum protocol dictates.

    How would I step through a string using a loop to compare the string to an array named vowel, containing "aeiou?" It's really bothering me that it was only comparing the first element, "a," to the string. I will get a chance to write a little test program tomorrow afternoon to test your way that you explained to me, and get back to you with any issues about that, then.

  4. #19
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Counting characters help

    Quote Originally Posted by LogicWavelength View Post
    By all means, if you have a better way, let me know!! It's not required for our class, but I like to throw everything in there to make my final programs appear more... real. I wrote it a few months ago with a lot less knowledge, and I'm sure I could tweak it a little, but that takes time, which I don't have. What I mean is when I run my program and answer the first question with 'y', it does this:

    Would you like to run this program (y/n)?: y
    There were 0 vowels and 0 consonants in the string.
    There were 0 total characters in the string.
    Would you like to run this program again (y/n)?:
    Press any key to continue...
    The code you showed doesn't ever call your counting functions.

  5. #20
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Counting characters help

    Quote Originally Posted by LogicWavelength View Post
    How would I step through a string using a loop to compare the string to an array named vowel, containing "aeiou?"
    This is less of a C++ problem, and more of a logical thinking issue.
    Code:
    Let u be the user input, and u(n) is character at position n within the user input:
    
    Set i to 0
    For each character at position i in the user input
    begin
       if ( strchr("aeiou", u(i) ) ) is not 0
           then u(i) is a vowel 
            else 
               u(i) is a consonant
       add 1 to i
    end
    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 5th, 2011 at 10:06 PM.

Page 2 of 2 FirstFirst 12

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