Count Vowel Questions

I seem to be having difficulty with my code, I have tried many different ways but I can't seem to figure out how to implement some things. I'm also not sure how to setup my menu so only certain functions are called.

1. Adding a if statement under ShowMenu to check to see if the string word is lowercase or uppercase. Also Is there a better method that allows spacing different string method?

2. Count Uppercase and Lowercase

3. Converting to Uppercase and lower case


I just can't seem to find out how to check to see my string is upper or lowercase. If i try to enter a space and another word it doesn't work then. If anyone can recommend a different string method I would appreciate it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 #include <iostream> //cout and cin
#include <string>  //for string use
#include <conio.h> //for getch
#include <cctype> // for library reference
using namespace std;

//Function Prototype
void CountVowels(string, int&);
void ShowMenu(string&, int);

int main()
{
	//Variables
	string word;
	int choice = 0;
	int vowels;

	//Call Functions
	ShowMenu(word, choice);
	CountVowels(word,vowels);

	_getch();
}
//***************************************************
// The function definition ShowMenu.
// Parameter word holds the word entered by user
// Parameter choice holds the users choice for menu
// A menu is displayed and asks the user for a response
//***************************************************
void ShowMenu(string& word, int choice)
{
	cout <<"\t\tMENU\t\t" << endl
		 <<"======================================" << endl;
	cout <<"1. Count Vowels" << endl
		 <<"2. Count uppercase" << endl
		 <<"3. Convert to uppercase" << endl
		 <<"4. Count lowercase" << endl
		 <<"5. Extract Word" << endl
		 <<"6. Quit" << endl;
	//Get menu choice and get word from user.
	cout << endl;
	cout <<"Enter choice: ";
	cin >> choice;
	cout << endl;
	cout << "Enter a word: ";
	cin >> word;


}
//------------------------------------------------------------
//  The function definition ShowMenu
//	Counts the number of vowels in a word
//	parameter  word  - a string of characters
//	parameter vowelCount  - number of vowels found in word 
//------------------------------------------------------------
void CountVowels(string word, int& vowelCount)
{
	vowelCount = 0;
	int numLetters = word.length();  //get the number of letters in a word

	for (int i = 0; i < numLetters; i++)
	{
		char letter = word[i];  //get the ith letter in the word

		if (letter == 'a' || letter == 'e' || 
		    letter == 'i' || letter == 'o' || 
		    letter == 'u' || letter == 'y' )
	      {
		   vowelCount++;
	      }
	 }
	 cout << "There are:" << vowelCount << endl;
}

Last edited on
closed account (Dy7SLyTq)
checking to see if its uppercase or lowercase: using <cctypes> you can use islower and isupper. im confused by the second part of one. do you mean split it up by spaces? i think string::tokenize does that. if not you can write one with <sstream>. not too hard. as to 2...
for(char C : ur_string) if(isupper(C)) uppercount++ and just do tests like that for lower. use toupper and tolower for converting between upper and lower
Thanks for the reply. How can I check for Uppercase from a string because I'm now sure how to check a string.
Topic archived. No new replies allowed.