Hi,
First year programming here and ran into some trouble that I can't seem to figure out. The purpose of the program is to ask the user to type in a string of letters and use my own function that makes the program sort out each individual word and outputs whether or not it's a vowel. My program works. But when you type in a string such as "Hello" there's an extra line that gets out putted and it just says " is a consonant.". I think it's grabbing a newline somewhere and it has to be ignored by using cin.ignore('/n'). Can't figure it out.
I tried that in some test code and couldn't get anything to work. In bool isVowel(char func) I tried if(func == '\n') { cin.clear(); } else{ switch(func){ .....} }, but it still just kept printing the newline character.
Thanks bcrawford. I was able to finish the rest of the program with your help. The purpose of the program was to make it so that a user types in a series of letters and the program would tell you what is a vowel and what is a consonant. Then at the very end it would tell you how many vowels total were typed. I added a counter and was able to complete the program. Thanks!
Can I make a suggestion, if you can change it or add it as I'm not sure if this is for school or just a fun app you are doing for yourself. If it was school I didn't know what all you have learned so far. Inside the boolean function instead of all the if statements why not go with a switch statement?
Just for clarification, I noticed in one of your earlier posts you were trying to use
cin.clear();
the clear() function is for clearing any errors that may have occurred when using fstreams for input or output ( ex. EOF(), fail(), bad() ) to be able to continue reading or writing. It won't stop the process of reading like you were trying to use it.
Yeah I was going off a bad reference I googled for flushing cin and got that. Also break shouldn't make a difference. When the program gets to a return it should automatically jump out of the function or block it is in.
It will never go to the last standard output string because of the return. Same with the switch statement. Soon as it hits return it is done, no need for the break;
By looking at the name of your variable I assume that you only want to get a letter. cin() gets a letter and a string and the string is a constant so is your "Hello". In that case I would try getchar().