this is my current code.
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
|
#include <iostream>
#include <cstring>
using namespace std;
int vowelCount(char*);
int consonantCount(char*);
int main()
{
const int length = 100;
char sentence[length];
int vowel=0, consonant=0, allLetters=0;
char choice;
bool not_done=true;
cout << "Enter a sentence: ";
cin.getline(sentence, length);
while(not_done){
vowel = vowelCount(sentence);
consonant = consonantCount(sentence);
allLetters = vowel + consonant;
cout << "\tMenu\n";
cout << "A) Count the number of vowels in the string\n";
cout << "B) Count the number of consonants in the string\n";
cout << "C) Count both the vowels and consonants in the string\n";
cout << "D) Enter another string\n";
cout << "E) Exit the program\n";
cout << "Enter your choice: ";
cin >> choice;
switch(choice)
{
case 'a':
case 'A':
cout<<"Number of vowels is " << vowel << endl;
break;
case 'b':
case 'B':
cout<<"Number of consonants is " <<consonant <<endl;
break;
case 'c':
case 'C':
cout<< "Number of letters is " << allLetters << endl;
break;
case 'd':
case 'D':
cout<< "Enter a new sentence: ";
cin.getline(sentence, length);
break;
case 'e':
case 'E':
not_done=false;
break;
default:
cout << "Error: '" << choice << "' is an invalid selection -";
cout << "try again"<< endl << endl;
break;
}
};
return 0;
}
//function definitions
|
the initial sentence entered works with the menu options but the option "d" where a new sentence is entered still doesn't work. here is what happens when it compiles:
Enter a sentence: hi there
Menu
A) Count the number of vowels in the string
B) Count the number of consonants in the string
C) Count both the vowels and consonants in the string
D) Enter another string
E) Exit the program
Enter your choice: d
Enter a new sentence: Menu
A) Count the number of vowels in the string
B) Count the number of consonants in the string
C) Count both the vowels and consonants in the string
D) Enter another string
E) Exit the program
Enter your choice:
it simply skips right back to the menu, I've tried rearranging the code a bunch but can't figure out what I need to change to make it work. any help would be appreciated, and thank you for the help so far.