Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Name: Maya Embar
- // Class: CIS 2541
- // Assn: Lab #9, #6
- // Date: 12/06/06
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int letterCount(char *, bool);
- int main()
- {
- char string[100], choice;
- bool exit = false;
- cout << "Letter Count Application Thingy: " << endl << endl;
- cout << "Enter a string of words so the stupid program can count the letters: ";
- cin.getline(string,99);
- //Choices Menu
- while (exit==false)
- {
- cout << endl
- << "A) Count Number of Vowels" << endl
- << "B) Count Number of Consonants" << endl
- << "C) Count Number of Consonants and Vowels" << endl
- << "D) Enter New String" << endl
- << "E) Exit Menu" << endl
- << "Please Make a Selection: ";
- cin >> choice;
- cin.ignore();
- choice = tolower(choice);
- while (choice != 'a' && choice != 'b' && choice != 'c'
- && choice != 'd' && choice != 'e')
- {
- cout << endl << "Only pick one of the Bloody Choices that were given!";
- choice = tolower(choice);
- }
- cout << endl;
- if (choice == 'a' || choice == 'c')
- cout << "There are " << letterCount(string,true) << "vowels in that sentence."
- << endl << endl;
- if (choice == 'b' || choice == 'c')
- cout << "There are " << letterCount(string,true) << "consonants in that sentence."
- << endl << endl;
- if (choice == 'd')
- {
- cout << "Please enter a new sentence: ";
- cin.getline(string,99);
- if (choice == 'e')
- exit = true;
- }
- system("pause");
- return 0;
- }
- int letterCount(char *array, bool vowel)
- {
- int length, count=0;
- length = strlen(array);
- for (int i=0; i<length; i++)
- {
- if (tolower(array[i]) == 'a' ||
- tolower(array[i]) == 'e' ||
- tolower(array[i]) == 'i' ||
- tolower(array[i]) == 'o' ||
- tolower(array[i]) == 'u')
- {
- if (vowel == true)
- count++;
- }
- else
- {
- if (isalpha(array[i]) > 0)
- {
- if (vowel == false)
- count++;
- }
- }
- }
- return count;
- }
Add Comment
Please, Sign In to add comment