#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
int main(void)
{
char gesture[3][10] = { "scissor", "stone", "cloth" };
int man, computer, result, ret;
srand(time(NULL));
while (1)
{
computer = rand() % 3;
printf("\nInput your gesture (0-scissor 1-stone 2-cloth): \n");
ret = scanf_s("%d", &man);
if ((ret != 1) || (man < 0) || (man > 2))
{
printf("Invalid input! Please input 0, 1 or 2. \n");
fflush(stdin); //刷新scanf缓冲区,准备重新输入。
continue;
}
printf("Your gesture: %s\tComputer's gesture: %s\n", gesture[man], gesture[computer]);
result = (man - computer + 4) % 3 - 1; //结果用来判断输赢, 1赢, 0平,-1输。
if (result > 0)
{
printf("You win!\n");
}
else if (result == 0)
{
printf("Draw!\n");
}
else
{
printf("You lose!\n");
}
}// end while
getchar();
return 0; // return
}// end main