Guest User

Untitled

a guest
Feb 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. // Name: Maya Embar
  2. // Class: CIS 2541
  3. // Assn: Lab #9, #6
  4. // Date: 12/06/06
  5.  
  6. #include <iostream>
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10.  
  11. int letterCount(char *, bool);
  12.  
  13. int main()
  14. {
  15. char string[100], choice;
  16. bool exit = false;
  17.  
  18. cout << "Letter Count Application Thingy: " << endl << endl;
  19.  
  20. cout << "Enter a string of words so the stupid program can count the letters: ";
  21. cin.getline(string,99);
  22.  
  23. //Choices Menu
  24. while (exit==false)
  25. {
  26. cout << endl
  27. << "A) Count Number of Vowels" << endl
  28. << "B) Count Number of Consonants" << endl
  29. << "C) Count Number of Consonants and Vowels" << endl
  30. << "D) Enter New String" << endl
  31. << "E) Exit Menu" << endl
  32. << "Please Make a Selection: ";
  33.  
  34. cin >> choice;
  35. cin.ignore();
  36. choice = tolower(choice);
  37.  
  38. while (choice != 'a' && choice != 'b' && choice != 'c'
  39. && choice != 'd' && choice != 'e')
  40. {
  41. cout << endl << "Only pick one of the Bloody Choices that were given!";
  42. choice = tolower(choice);
  43. }
  44.  
  45. cout << endl;
  46.  
  47. if (choice == 'a' || choice == 'c')
  48. cout << "There are " << letterCount(string,true) << "vowels in that sentence."
  49. << endl << endl;
  50.  
  51. if (choice == 'b' || choice == 'c')
  52. cout << "There are " << letterCount(string,true) << "consonants in that sentence."
  53. << endl << endl;
  54.  
  55. if (choice == 'd')
  56. {
  57. cout << "Please enter a new sentence: ";
  58. cin.getline(string,99);
  59.  
  60. if (choice == 'e')
  61. exit = true;
  62. }
  63.  
  64. system("pause");
  65.  
  66. return 0;
  67. }
  68.  
  69.  
  70. int letterCount(char *array, bool vowel)
  71. {
  72. int length, count=0;
  73. length = strlen(array);
  74.  
  75. for (int i=0; i<length; i++)
  76. {
  77. if (tolower(array[i]) == 'a' ||
  78. tolower(array[i]) == 'e' ||
  79. tolower(array[i]) == 'i' ||
  80. tolower(array[i]) == 'o' ||
  81. tolower(array[i]) == 'u')
  82. {
  83. if (vowel == true)
  84. count++;
  85. }
  86. else
  87. {
  88. if (isalpha(array[i]) > 0)
  89. {
  90. if (vowel == false)
  91. count++;
  92. }
  93. }
  94. }
  95. return count;
  96. }
Add Comment
Please, Sign In to add comment