Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3.  
  4. using namespace std;
  5.  
  6. void firstChoice(char []);
  7.  
  8. int main()
  9. {
  10. int choice;
  11. int answer;
  12. const int SIZE = 100;
  13. char line[SIZE];
  14.  
  15.  
  16. do
  17. {
  18. cout << "1. Adds numbers but ignores anything thats not a number." << endl;
  19. cout << "2. Count the number of consonants in a string." << endl;
  20. cout << "3. Counts the vowels in a string." << endl;
  21. cout << "4. Counts whitespace characters in a string." << endl;
  22. cout << "Enter a number to access that program or 0 to end it: ";
  23. cin >> choice;
  24.  
  25. switch(choice)
  26. {
  27. case 1:
  28. cout << "nEnter a string: ";
  29. cin.getline(line, SIZE);
  30. firstChoice(line);
  31. break;
  32.  
  33. case 2:
  34. cout << "Enter a string: ";
  35. cin.getline(line, SIZE);
  36. break;
  37.  
  38. case 3:
  39. cout << "Enter a string: ";
  40. cin.getline(line, SIZE);
  41. break;
  42.  
  43. case 4:
  44. cout << "Enter a string: ";
  45. cin.getline(line, SIZE);
  46. break;
  47. }
  48. }
  49. while(choice != 0);
  50. return 0;
  51. }
  52.  
  53. void firstChoice(char line[])
  54. {
  55. int size2 = 0;
  56. int sum = 0;
  57.  
  58. while(line[size2] != '')
  59. {
  60. if(isalpha(line[size2]))
  61. {
  62. line[size2] = 0;
  63. }
  64. sum += line[size2];
  65.  
  66. size2++;
  67. }
  68. cout << sum;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement