fork download
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. int main(int argc, char *argv[]) {
  6. int player, comp;
  7. const char *choices[] = {"paper", "scissor", "stone"};
  8.  
  9. printf("Enter your choice (0: paper, 1: scissor, 2: stone):\n");
  10. scanf("%d", &player);
  11.  
  12. srand(time(NULL));
  13. comp = rand() % 3;
  14.  
  15. if (((player + 3) - comp) % 3 == 2) {
  16. printf("Lose!\n");
  17. } else if (((player + 3) - comp) % 3 == 1) {
  18. printf("Win!\n");
  19. } else {
  20. printf("Draw!\n");
  21. }
  22. printf("%s (player) vs. %s (compuper)\n", choices[player], choices[comp]);
  23.  
  24. return 0;
  25. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty