|
-
April 5th, 2011, 07:56 PM
#16
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...
-
April 5th, 2011, 08:00 PM
#17
Re: Counting characters help
 Originally Posted by LogicWavelength
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
-
April 5th, 2011, 08:17 PM
#18
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.
-
April 5th, 2011, 08:37 PM
#19
Re: Counting characters help
 Originally Posted by LogicWavelength
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.
-
April 5th, 2011, 10:00 PM
#20
Re: Counting characters help
 Originally Posted by LogicWavelength
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|