8,石头,剪刀,布的逻辑代码

//石头,剪刀,布

#include

#include


int main(int argc,const char * argv[]) {

    int cmp =arc4random_uniform(3);//会产生012代表 石头,剪刀,布

    printf("请您出拳:(0,1,2)\n");

    int person;

    scanf("%i",&person);

    printf("cmp = %i,person = %i\n",cmp,person);

    if(person == cmp ){

        printf("平局\n");

    }else if((0 == person && 2 == cmp)||(1 == person && 3 == cmp)||(3 == person || 1 == cmp)){

        printf("玩家赢了!\n");

    }else{

        printf("电脑赢了!\n");

    }

}

你可能感兴趣的:(C语言)