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