Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (bibby):

Urgent c++ problem http://pastebin.com/8ccBxr2q I'm trying to understand how to get case 'd' to work

OpenStudy (bibby):

http://pastebin.com/8ZmswaZ2

OpenStudy (bibby):

the fixed code is #include <iostream> #include <cctype> #include <cstdlib> using namespace std; void mypause(void); int specialCounter(char *foo, int &consonants); bool isVowel(char c); void menu(); int main() { const int BUFFER = 251; //Array size char str[BUFFER]; // To hold the string char decision; int consonants; bool flag = true; cout << "Please enter a string (up to 250 characters): " << endl; cin.getline(str, BUFFER); int vowels = specialCounter(str, consonants); do { menu(); cin >> decision; switch(decision) { case 'a': case 'A': cout << vowels << " vowels\n\n"; break; case 'b': case 'B': cout << consonants << " consonants\n\n"; break; case 'c': case 'C': cout << vowels << " vowels\t " << consonants << " consonants\n\n"; break; case 'd': case 'D': cout << "Please enter a string (up to 250 characters): " << endl; cin.ignore(); cin.getline(str, BUFFER); vowels = specialCounter(str, consonants); break; case 'e': case 'E': flag = false; break; default: cout << "Invalid choice\n"; } mypause(); }while(flag); return 0; } void menu() { cout << "ALPHABETIC VOWEL/CONSONANT COUNTER. NO NUMBERS ALLOWED NERD\n"; cout << "\nA) Count the number of vowels in the string\n"; cout << "B) Count the number of consonants in the string\n"; cout << "C) Count both the vowels and consonants in the string\n"; cout << "D) Enter another string\n"; cout << "E) Exit the program\n\n"; } bool isVowel(char c) { switch(c) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': return true; } return false; } int specialCounter(char *foo, int &consonants) { int vowels = 0; consonants = 0; while (*foo) { isVowel(*foo) ? vowels++ : consonants++; foo++; } return vowels; } void mypause(void)// Function mypause() { system("pause"); return; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!