fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7. std::vector<std::string> computer_atcions = {"paper", "scissors", "stone"};
  8. std::string user_input = "";
  9. int result = 0;
  10. int won_count = 0;
  11. int loss_count = 0;
  12. std::cout << "Please, input paper, scissors or stone: ";
  13. for(int i = 0; i < computer_atcions.size(); i++)
  14. {
  15. std::cin >> user_input;
  16. if (user_input != "paper" && user_input != "scissors" && user_input != "stone")
  17. {
  18. std::cout << "Please, input paper, scissors or stone: ";
  19. continue;
  20. }
  21.  
  22. computer_atcions.push_back(user_input);
  23.  
  24. if (user_input == computer_atcions[i])
  25. {
  26. std::cout << user_input << " draw " << computer_atcions[i] << std::endl;
  27. }
  28. else if (user_input == "paper" && computer_atcions[i] == "stone")
  29. {
  30. std::cout << user_input << " beats " << computer_atcions[i] << std::endl;
  31. won_count++;
  32. }
  33. else if (user_input == "paper" && computer_atcions[i] == "scissors")
  34. {
  35. std::cout << user_input << " loses to " << computer_atcions[i] << std::endl;
  36. loss_count++;
  37. }
  38. else if (user_input == "stone" && computer_atcions[i] == "scissors")
  39. {
  40. std::cout << user_input << " beats " << computer_atcions[i] << std::endl;
  41. won_count++;
  42. }
  43. else if (user_input == "stone" && computer_atcions[i] == "paper")
  44. {
  45. std::cout << user_input << " loses to " << computer_atcions[i] << std::endl;
  46. loss_count++;
  47. }
  48. else if (user_input == "scissors" && computer_atcions[i] == "paper")
  49. {
  50. std::cout << user_input << " beats " << computer_atcions[i] << std::endl;
  51. won_count++;
  52. }
  53. else if (user_input == "scissors" && computer_atcions[i] == "stone")
  54. {
  55. std::cout << user_input << " loses to " << computer_atcions[i] << std::endl;
  56. loss_count++;
  57. }
  58. else
  59. {
  60. std::cout << "debug" << std::endl;
  61. break;
  62. }
  63.  
  64. std::cout << "You have lost " << loss_count << " and won " << won_count << " games." << std::endl;
  65.  
  66. //std::cout << computer_atcions[i] << user_input << std::endl;
  67. }
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Please, input paper, scissors or stone: Please, input paper, scissors or stone: Please, input paper, scissors or stone: Please, input paper, scissors or stone: