paper rock scissors

so i started to learn how to code using c++ like 2 days ago
and i thought i could write paper rock scissors

what do you guys think ?
is there an easier way to writing this code?

http://cpp.sh/2cc3

Yes, with some modulo-3 algebra magic:
1
2
3
4
5
6
7
8
9
10
11
int a_pick, b_pick;

// TODO: put user input in a_pick and b_pick.

static const char * const plays[] = { "rock", "paper", "scissors" };
std::cout << "A has picked " << plays[a_pick] << "\n"
    "B has picked " << plays[b_pick] << std::endl;

static const char * const states[] = { "Tie.", "A win.", "B win." };
int state = (a_pick + 3 - b_pick) % 3;
std::cout << states[state] << std::endl;
Last edited on
Topic archived. No new replies allowed.