代码展示:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
//石头0,剪刀1,布2的游戏
int u_select=0;
int p_select=0;
int p=0,u=0; //设置俩个变量作为用户或电脑胜利的判定
printf("请用户输入0.石头,1.剪刀,2.布三者中其一:\n");
//先赢三场者胜利
while(p<3&&u<3)
{
scanf("%d",&u_select); //通过键盘让用户进行输入
srand(time(NULL)); //随机函数rand();使用srand()进行随机播种
p_select=rand()%3; //对随机函数给出的数值取余得到0,1,2,的随机数
switch(p_select)
{
case 0:
{
if(0==u_select)
{
printf("平局\n");
}
else if(1==u_select)
{
printf("电脑赢一局\n");
p++;
}
else if(2==u_select)
{
printf("用户赢一局\n");