+ 2
I want to count the number of vowels from multiple inputs from user's choice but my code ain't doing it
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.
+ 1
Yes, like this getline(cin,variableName) instead of cin >> variableName
+ 1
Okay, so you forgot to reset the count variable at the end. Try to run the code again.
+ 1
Tsering thank you so much it is working perfectly now
0
Jayakrishna🇮🇳 I still get an error😭
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
0
Tsering so you basically saying no one can solve this here?
It's impossible?
0
Did you run the code I posted?
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
0
That is because you have to give the input like this:
YourWordWithoutSpace
end
0
Tsering the word 'yes' is without space though
0
Make sure to enter 'end' in newline
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
0
Use getline() function
0
How?
You mean for asking for an input?
0
Tsering I should just change that part on while loop only?
0
Yes
0
Tsering the user doesn't get a chance for an input if I do that the code just run prints out 0's
0
Check the code, i just updated it.