帮我写一个剪刀石头布游戏
时间: 2023-03-30 15:01:22 浏览: 117
好的,我可以帮你写一个剪刀石头布游戏。以下是代码示例:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int player, computer;
int result;
srand(time(NULL));
printf("欢迎来玩剪刀石头布游戏!\n");
printf("请出拳:\n");
printf("1.剪刀 2.石头 3.布\n");
scanf("%d", &player);
computer = rand() % 3 + 1;
printf("你出的是");
switch (player)
{
case 1:
printf("剪刀\n");
break;
case 2:
printf("石头\n");
break;
case 3:
printf("布\n");
break;
default:
printf("无效的选择\n");
return ;
}
printf("电脑出的是");
switch (computer)
{
case 1:
printf("剪刀\n");
break;
case 2:
printf("石头\n");
break;
case 3:
printf("布\n");
break;
}
result = (player - computer + 3) % 3;
if (result == )
{
printf("平局\n");
}
else if (result == 1)
{
printf("你赢了!\n");
}
else
{
printf("你输了!\n");
}
return ;
}
阅读全文