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.
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?
Couning Uppercase and Lowercase
Converting from Uppercase to Lowercase and vice versa
I just can't seem to find out how to check to see my string is upper or lowercase. My string only accepts one word and no spaces. I can't figure out how to have the menu so each choice calls a certain function.
' #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;
}
`