Create a simple function...Please make it simple to understand!!! its for a beggining course in C++...create a function that allows the user to input text and that output the number of vowels that were entered.
create an array of characters and go down the list using an 'or' statement int numberofvouls = 0 int x for(x = 0; x < number of characters; x++) if(char = a || e || i || o || u || y) { cout << "voul baby!" << endl; numberofvouls++ } ..... something on that matter Bill
We won't do your homework for you. Post what you've got so far and show where you're stuck and what you don't understand. If you're really stuck why not ask the teacher, that's what he's paid for.
Here is simple function:---------- Code: void total_vowels() { char string[80]; cout<<"\n enter your text\n"; cin>>string; int novowels = 0 int x for(x = 1; x <=80; x++) { if(string[x]== a || e || i || o || u ) { novowels++ } } cout<<"total no of vowels is :"<<novowels; }
Simple yes, but did you actually try compiling it? I'd be interested to know what language accepts if(string[x]== a || e || i || o || u || y) as valid, and whether or not you got any kind of error on "novowels++". OP, if you want to learn, where are you stuck? Post what you've got so far, let us know what you're struggling with and we'll explain it to you.
Yes, the above program posted by me is wrong. My mistake is in if statement. I have rectify it in this program.... Code: void total_vowels() { char string[80]; cout<<"\n enter your text\n"; cin>>string; int novowels = 0 int x for(x = 1; x <=79; x++) { if(string[x]== 'a' || string[x]== 'e' || string[x]== 'i' || string[x]== 'o' || string[x]== 'u') { novowels++ } } cout<<"total no of vowels is :"<<novowels; }
You still haven't compiled and run the program; I can still see at least one very obvious syntax error. Try building and running it, and make sure it produces the required output, THEN AND ONLY THEN is it a good idea to consider posting the result. Correction: three syntax errors, each of which will throw a compile time error, unless your compiler is VERY slack.
Your compiler is very slack then, because the following three statements should be terminated with a semicolon: Code: int novowels = 0 int x novowels++ What if you call the function twice, the first time entering the string "sausage" then on the second call "apple"? Do you get the correct scores 4 and 2? Edit: whoops, on second thoughts, no that won't show the bug I'm thinking of. Try aaaaaaaaaa and aaaaa (10 and 5 a's respectively). This should give you the results 10 and 5, but on inspection of the code I think you won't get these results.
A non-debug build in Visual Studio 2005, fixing the above three syntax errors, gives the expected results 9 and 8. Can you see why?