fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. inline bool yes_counter( char ch )
  5. {
  6. return ch == 'Y' || ch == 'y';
  7. }
  8.  
  9. int main()
  10. {
  11. int const & counter = 10;
  12. int yc = 0, nc = 0;
  13. std::string votes {};
  14.  
  15. std::cout << "Enter a string of Yes and No votes: ";
  16. std::getline( std::cin, votes );
  17. votes.resize( counter ); //make sure input is exactly 10.
  18.  
  19. yc = std::count_if( votes.cbegin(), votes.cend(), yes_counter );
  20. nc = std::count_if( votes.cbegin(), votes.cend(), []( char ch ) { return ch == 'N' || ch == 'n'; } );
  21.  
  22. std::cout << "Yes votes amount to " << yc << ", and No votes amount to " << nc << std::endl;
  23. std::cout << "\tNumbers of Yes votes: " << std::string ( yc, '*' ) << std::endl;
  24. std::cout << "\tNumbers of No votes: " << std::string ( nc, '*' ) << std::endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3276KB
stdin
YyyNnYnyNY
stdout
Enter a string of Yes and No votes: Yes votes amount to 6, and No votes amount to 4
	Numbers of Yes votes: ******
	Numbers of No votes: ****