I want to count the number of vowels from multiple inputs from user's choice but my code ain't doing it
25 Answers
New Answerhttps://code.sololearn.com/cn55m3UG5a6f/?ref=app
5/24/2022 8:17:51 PM
Siyabonga Brian25 Answers
New AnswerYour 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.
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
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
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
Tsering the user doesn't get a chance for an input if I do that the code just run prints out 0's
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message