my counter isn't working
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey can you help me figure our why my counter isn't working?
If i input find_consonant('tiger') I need MATLAB to count all of the letters that are not a, e, i, o, u. So the answer should be 3 but my code is not counting right. Thanks for any suggestions.
function count=find_consonant(word)
count=0;
for i=1:length(word);
if word(i)~='a'||word(i)~='e'||word(i)~='i'||word(i)~='o'||word(i)~='u'
count=count+1;
else
count=count;
end
end
0 Kommentare
Akzeptierte Antwort
Matt J
am 4 Okt. 2016
Bearbeitet: Matt J
am 4 Okt. 2016
Use && instead of | |
3 Kommentare
Matt J
am 4 Okt. 2016
Bearbeitet: Matt J
am 4 Okt. 2016
I came to that solution because there were no other candidates. OR will clearly not work, because you are then requiring only that the given letter be different from at least one of the vowels, be it A or E or I or O or U. Any letter will in fact satisfy this. A consonant, however, must be simultaneously different from all of them.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!