I want to count the number of vowels from multiple inputs from user's choice but my code ain't doing it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I want to count the number of vowels from multiple inputs from user's choice but my code ain't doing it

https://code.sololearn.com/cn55m3UG5a6f/?ref=app

24th May 2022, 8:17 PM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
25 Answers
+ 3
Your code don't have that way check.. for(int i = 0; i < s_word.length(); i = i + 1){ if(int i = 0; i < mylist.size(); i = i + 1){ // what is this? Is it loop but typo? You have i already declared in first loop.. You must have next condition for check vowel here. count = count + 1; } } Try like this: for(int i = 0; i < s_word.length(); i = i + 1){ for(int j= 0; j < mylist.size(); j= j + 1){ if(s_word[i] == mylist[j] ) count = count + 1; } } Before this, take list of character, not string of characters.. Otherwise comparing with character with string is invalid.. edit: seems, unlike otherlanguages, if mylist is a list, then I think c++ not support index approach for list. the c++ way is to use iterator for list instead of for(int j= 0; j < mylist.size(); j= j + 1){ use for(auto j = mylist.begin(); j!=mylist.end(); j = j + 1){ or for(string s : mylist) { .. } check now. hope it help.
24th May 2022, 8:29 PM
Jayakrishna 🇮🇳
+ 1
Yes, like this getline(cin,variableName) instead of cin >> variableName
25th May 2022, 1:10 AM
Lama
Lama - avatar
+ 1
Okay, so you forgot to reset the count variable at the end. Try to run the code again.
25th May 2022, 2:35 AM
Lama
Lama - avatar
+ 1
Tsering thank you so much it is working perfectly now
25th May 2022, 2:37 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
Jayakrishna🇮🇳 I still get an error😭
24th May 2022, 8:44 PM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
First, you can't access list with index. Second, the compiler is complaining about comparing int to long unsigned int. I've fixed the code. https://code.sololearn.com/clFh6wTK292G/?ref=app
25th May 2022, 12:08 AM
Lama
Lama - avatar
0
Tsering so you basically saying no one can solve this here? It's impossible?
25th May 2022, 12:11 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
Did you run the code I posted?
25th May 2022, 12:31 AM
Lama
Lama - avatar
0
Tsering yess I did run it,let's take I input a word "yes" instead of giving me the output 1 since there's only one vowel on word "yes" it give me output of 1,2,3,........ you infinity
25th May 2022, 12:33 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
That is because you have to give the input like this: YourWordWithoutSpace end
25th May 2022, 12:46 AM
Lama
Lama - avatar
0
Tsering the word 'yes' is without space though
25th May 2022, 12:48 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
Make sure to enter 'end' in newline
25th May 2022, 12:51 AM
Lama
Lama - avatar
0
Tsering so how can I fix it for the case of a sentence with spaces? cause the task was to get a string from the user any type not just a word
25th May 2022, 12:55 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
Use getline() function
25th May 2022, 1:00 AM
Lama
Lama - avatar
0
How? You mean for asking for an input?
25th May 2022, 1:08 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
25th May 2022, 1:08 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
Tsering I should just change that part on while loop only?
25th May 2022, 1:14 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
Yes
25th May 2022, 1:15 AM
Lama
Lama - avatar
0
Tsering the user doesn't get a chance for an input if I do that the code just run prints out 0's
25th May 2022, 1:17 AM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
Check the code, i just updated it.
25th May 2022, 1:20 AM
Lama
Lama - avatar