Count how many vowels and consonants occur in a string: Difference between revisions

Content added Content deleted
(Add CLU)
Line 357: Line 357:


</pre>
</pre>

=={{header|CLU}}==
<lang clu>ucase = proc (c: char) returns (char)
if c>='a' & c<='z' then return(char$i2c(char$c2i(c)-32))
else return(c)
end
end ucase

letter = proc (c: char) returns (bool)
c := ucase(c)
return(c >= 'A' & c <= 'Z')
end letter

vowel = proc (c: char) returns (bool)
return(string$indexc(ucase(c), "AEIOU") ~= 0)
end vowel

consonant = proc (c: char) returns (bool)
return(letter(c) & ~vowel(c))
end consonant

vowels_and_consonants = proc (s: string) returns (int,int)
vs: int := 0
cs: int := 0
for c: char in string$chars(s) do
if vowel(c) then vs := vs+1
elseif consonant(c) then cs := cs+1
end
end
return(vs,cs)
end vowels_and_consonants

example = proc (s: string)
po: stream := stream$primary_output()
v, c: int := vowels_and_consonants(s)
stream$putl(po, "\"" || s || "\": " || int$unparse(v)
|| " vowels, " || int$unparse(c)
|| " consonants.")
end example

start_up = proc ()
example("If not now, then when? If not us, then who?")
end start_up</lang>
{{out}}
<pre>"If not now, then when? If not us, then who?": 10 vowels, 20 consonants.</pre>


=={{header|Cowgol}}==
=={{header|Cowgol}}==