So I have a project due here soon.
It is on the topic of coding a program that allows the user to enter as many letters as they would like; one at a time.
I coded it, but I'm having trouble with the actual tally system itself not counting how many vowels are entered. It seems a mess in general, any help is definitely appreciated.
The commenting and labeling are required by the professor for reference.
In other words:
IF user gives a vowel, then nothing is shown.
ELSE (not a vowel), then count is shown.
What if the input is "aaaaaaaaaa"? Nothing will be shown, because they all are vowels.
Oh, it gets better:
1 2 3 4
do {
int vowelcount = 0;
cout << Print(vowelcount);
} while ...
The vowelcount is 0 at start of each iteration. Only non-vowels print, so the only possible output is 0.
IMHO, the program should either show count after each input or show count only once after all input. Your choice.
1 2 3 4 5 6 7 8 9
int vowelcount = 0;
do {
if ( something ) {
++vowelcount;
}
cout << vowelcount; // either after each letter
} while ( goAgain() );
cout << vowelcount; // or only once after all letters
void CounterVowel(int vowelcount) {
do {
char letter;
GetChar(letter);
if ( IsVowel(letter) ) {
vowelcount++;
}
} while (goAgain() == true);
cout << "Results: ";
Print(vowelcount);
}
my results:
Welcome to the program!
I, the computer, am going to
ask you to input some letters.
Then, I can tell you how many
vowels you entered.
Let's start:
Please enter a letter: a
Another letter? y/Y/n/N:
y
Please enter a letter: g
Another letter? y/Y/n/N:
n
Results: 1 vowels found.
Another letter? y/Y/n/N:
I think both your and user's life will be much easier if you try to grab all the characters typed until <Enter> key (hence the check against '\n') ;P
You also want to be careful to eat the rest of the line after the user decides to repeat or not -- he might enter "yNyNyNasdfasa" or something, and we're only grabbing a single character. The newline from user's hit of <Enter> key is still in play and could inadvertently be checked.
I've also added an alternate way to check vowel using a "fall-through" technique with switch statement, where break isn't needed because all paths lead to a return.
Welcome to the program!
I, the computer, am going to
ask you to input some letters.
Then, I can tell you how many
vowels you entered. Let's start!
Input a bunch of letters and press <Enter>
? Heyyyyyy, how's it going?!
Total vowels: 5
Again (y/n)? y
Input a bunch of letters and press <Enter>
? A bird in the hand is worth a hundred in the air.
Total vowels: 14
Again (y/n)? n
Bye!