| | |
Need help with counting " Y" as a vowel
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
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.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cctype> using namespace std; int Y(char string[], int ctr, int vowel); int length = 0; int vowel = 0; int main() { char string[50] = ""; cout << "Please enter a string of 50 characters or less: "; cin.getline(string, 50); length = strlen(string); for(int ctr = 0; ctr < length; ctr++) { string[ctr] = tolower(string[ctr]); if(string[ctr] == 'a' || string[ctr] == 'e' || string[ctr] == 'i' || string[ctr] == 'o' || string[ctr] == 'u') { vowel++; if(string[ctr] == 'y') { vowel = Y(string, ctr, vowel); } } if(string[ctr] == ' ') { vowel++; } } cout << "\nThe string you entered was: "<< string << endl; cout << "You entered " << (length - vowel) << " consonants in that string." << endl; } int Y(char string[], int ctr, int vowel) { bool flag1 = false; bool flag2 = false; if(string[ctr++] == 'a' || string[ctr++] == 'e' || string[ctr++] == 'i' || string[ctr++] == 'o' || string[ctr++] == 'u') { flag1 = true; } if(string[ctr--] == 'a' || string[ctr--] == 'e' || string[ctr--] == 'i' || string[ctr--] == 'o' || string[ctr--] == 'u') { flag2 = true; } if((flag1 == true) && (flag2 == true)) { vowel--; } return vowel; }
here is something just off the top of my head -- untested and uncompiled.
your program also needs to verify that (ctr-1) >= 0 && (ctr+1) <= length of the string.
C++ Syntax (Toggle Plain Text)
int isvowel(char c) { if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return TRUE; return FALSE; } ... ... if( string[ctr] == 'y' ) { if( !isvowel(strin[ctr-1]) && !isvowel(strin[ctr+1]) { // y is a vowel } }
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.
![]() |
Similar Threads
- vowel counting problem (C++)
- "click Counter" help Please (Visual Basic 4 / 5 / 6)
- "input signal out of range" at startup (Windows NT / 2000 / XP)
- google "keyword" question (Search Engine Optimization)
Other Threads in the C++ Forum
- Previous Thread: Dll's and problems with them
- Next Thread: help
| Thread Tools | Search this Thread |
Tag cloud for C++
api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference rpg simple string strings studio system temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






