It is supposed to count the characters in a userinput-string.
(i.e: if the user enters "stuff", the statistics will show that there is 1 "s", 1 "t", 1 "u" and 2 "f"s)
My problem is that the program outputs:
1 s
1 t
1 u
2 f
2 f
Wich is wrong. The correct output should be:
1 s
1 t
1 u
2 f
here's my code (with a pre-set string):
int main(int argc, char** argv)
{
std::string google = "google";
std::vector<char> chars(google.size());
std::vector<int> values(google.size());
for(unsigned int i = 0; i != google.length(); i++)
{
chars.at(i) = google.at(i);
}
for(unsigned int i = 0; i != google.length(); i++)
{
for(unsigned int j = 0; j != google.length(); j++)
{
if(chars.at(i) == google.at(j))
{
values.at(i)++;
}
}
}
for(unsigned int i = 0; i != google.length(); i++)
{
std::cout << chars.at(i) << " occurs " << values.at(i) << " times " << std::endl;
}
return 0;
}

New Topic/Question
Reply



MultiQuote




|