Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- cout << "test";
- cin.getline(str, BUFFER);
- cout << "\ntest\n";
- vowels = specialCounter(str, consonants);
- cout << "If we made it here the vowels were counted somehow...\n";
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment