histogram - Counting characters in words in a C++ console application -
this problem attempting solve:
ask user enter bunch of words, many want, until enter 0. after that, count how many times each letter appears across words, , print out list of each letter , how many times appears. example:
enter word> hello enter word> lemon enter word> goodbye enter word> 0 letter: h appears 1 times letter: e appears 3 times ...
so far have put words together, , have made comparisons. problem lies in that, after words put together, , 0 input, cannot count each invidual character within combined string. did research, , i've read perform need vectors, not understand how use them.
i've been trying @ week right, no avail. c++ sort of different other language have learned (at least me).
you can use std::unordered_map
, characters key , counter value. each string read, iterate on , increase value corresponding character in map.
this way don't need store words.
Comments
Post a Comment