fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string input;
  8. int num_black = 0, num_red = 0, num_white = 0;
  9.  
  10. do
  11. {
  12. cout << "input car color :";
  13. cin >> input;
  14.  
  15. if (input == "black") {
  16. ++num_black;
  17. }
  18. else if (input == "red") {
  19. ++num_red;
  20. }
  21. else if (input == "white") {
  22. ++num_white;
  23. }
  24.  
  25. cout << "continue input car color?" << endl;
  26. cin >> input;
  27. }
  28. while (input == "y");
  29.  
  30. cout << endl;
  31. cout << "detail car color" << endl;
  32. cout << setw(11) << left << "black" << num_black << " car" << (num_black != 1 ? "s" : "") << endl;
  33. cout << setw(11) << left << "red" << num_red << " car" << (num_red != 1 ? "s" : "") << endl;
  34. cout << setw(11) << left << "white" << num_white << " car" << (num_white != 1 ? "s" : "") << endl;
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5296KB
stdin
black y black y black y red y white n
stdout
input car color :continue input car color?
input car color :continue input car color?
input car color :continue input car color?
input car color :continue input car color?
input car color :continue input car color?

detail car color
black      3 cars
red        1 car
white      1 car