Need help with counting " Y" as a vowel

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 2
Reputation: newbie101 is an unknown quantity at this point 
Solved Threads: 0
newbie101 newbie101 is offline Offline
Newbie Poster

Need help with counting " Y" as a vowel

 
0
  #1
Nov 28th, 2006
I am trying to get this code working for extra credit, but I unfortunately only have 40 minutes until it is due:rolleyes:. I would like to know how to do this program, whether I turn it in or not. The letter "Y" can be considered a vowel if there is not a vowel immediately before or immediately after the "y", otherwise it should be considered a consonant. I have everything working except for the Y being counted as a vowel when it is next to consonants.

  1. #include <iostream>
  2. #include <cctype>
  3. using namespace std;
  4.  
  5. int Y(char string[], int ctr, int vowel);
  6. int length = 0;
  7. int vowel = 0;
  8.  
  9. int main()
  10. {
  11. char string[50] = "";
  12. cout << "Please enter a string of 50 characters or less: ";
  13. cin.getline(string, 50);
  14. length = strlen(string);
  15.  
  16. for(int ctr = 0; ctr < length; ctr++)
  17. {
  18. string[ctr] = tolower(string[ctr]);
  19.  
  20.  
  21. if(string[ctr] == 'a' || string[ctr] == 'e' || string[ctr] == 'i' || string[ctr] == 'o' || string[ctr] == 'u')
  22. {
  23. vowel++;
  24.  
  25. if(string[ctr] == 'y')
  26. {
  27. vowel = Y(string, ctr, vowel);
  28. }
  29. }
  30.  
  31. if(string[ctr] == ' ')
  32. {
  33. vowel++;
  34. }
  35.  
  36. }
  37. cout << "\nThe string you entered was: "<< string << endl;
  38. cout << "You entered " << (length - vowel) << " consonants in that string." << endl;
  39. }
  40.  
  41. int Y(char string[], int ctr, int vowel)
  42. {
  43. bool flag1 = false;
  44. bool flag2 = false;
  45. if(string[ctr++] == 'a' || string[ctr++] == 'e' || string[ctr++] == 'i' || string[ctr++] == 'o' || string[ctr++] == 'u')
  46. {
  47. flag1 = true;
  48. }
  49. if(string[ctr--] == 'a' || string[ctr--] == 'e' || string[ctr--] == 'i' || string[ctr--] == 'o' || string[ctr--] == 'u')
  50. {
  51. flag2 = true;
  52. }
  53. if((flag1 == true) && (flag2 == true))
  54. {
  55. vowel--;
  56. }
  57. return vowel;
  58. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,521
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1481
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need help with counting " Y" as a vowel

 
0
  #2
Nov 28th, 2006
>>but I unfortunately only have 40 minutes until it is due
unfortunately for you the time expired 6 hours ago. Lesson learned: don't wait until the last minute to get help.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 2
Reputation: newbie101 is an unknown quantity at this point 
Solved Threads: 0
newbie101 newbie101 is offline Offline
Newbie Poster

Re: Need help with counting " Y" as a vowel

 
0
  #3
Nov 28th, 2006
Well, I had a major project that was due as well as finals all this week, so I did not do the extra credit until everything else was finished. Anyway, I would still like to know how to do it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,521
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1481
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need help with counting " Y" as a vowel

 
0
  #4
Nov 28th, 2006
here is something just off the top of my head -- untested and uncompiled.
  1.  
  2. int isvowel(char c)
  3. {
  4. if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
  5. return TRUE;
  6. return FALSE;
  7. }
  8.  
  9. ...
  10. ...
  11. if( string[ctr] == 'y' )
  12. {
  13. if( !isvowel(strin[ctr-1]) && !isvowel(strin[ctr+1])
  14. {
  15. // y is a vowel
  16. }
  17. }

your program also needs to verify that (ctr-1) >= 0 && (ctr+1) <= length of the string.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC