C++编程问题,模拟石头、剪刀、布游戏,高手快进!

核心提示// 111801cpp : 定义控制台应用程序的入口点。//#include "stdafxh"#include <iostream>using namespace std;int main(){ char a,b; while(1){c

// 111801cpp : 定义控制台应用程序的入口点。

//

#include "stdafxh"

#include <iostream>

using namespace std;

int main()

{

char a,b;

while(1)

{

cin >> a ;

if(a == 'n')

return 0;

cin >> b;

if(a == 'b')

{

if(b == 'o')

cout << "第一个人赢" <<endl;

else if(b == 'b')

cout << "一样大" <<endl;

else cout << "等二个人赢" <<endl;

}

if(a == 'v')

{

if(b == 'b')

cout << "第一个人赢" <<endl;

else if(b == 'v')

cout << "一样大" <<endl;

else cout << "等二个人赢" <<endl;

}

if(a == 'o')

{

if(b == 'v')

cout << "第一个人赢" <<endl;

else if(b == 'o')

cout << "一样大" <<endl;

else cout << "等二个人赢" <<endl;

}

}

system("pause");

return 0;

}

用英语怎么说“剪刀石头布游戏”?

用1、2、3来表示剪刀、石头、布,然后先用scanf函数读取用户的输入,再用rand函数产生一个随机数,最后进行比较就可以了。

#include

#include

#include

void

main()

{

int

com,user;

char

c;

srand((unsigned)time(null));

//初始化随机数,如果没有这条语句,每次运行电脑产生的随机数序列都是一样的

printf("进入游戏n");

do{

printf("请出拳(1剪刀、2石头、3布):");

scanf("%d",&user);

com=rand()%3+1;

//产生1-3范围内的随机数

printf("电脑出%sn",com==1"剪刀":com==2"石头":"布");

switch(com-user)

//用电脑产生的数和用户输入的数的差值来判断胜负

{

case

0:

printf("平手n");

break;

case

1:

case

-2:

printf("电脑赢了n");

break;

case

-1:

case

2:

printf("你赢了n");

}

printf("继续游戏按y键、其它键退出");

getchar();

c=getchar();

}while(c=='y'

||

c=='y');

printf("已经退出游戏");

}

翻译如下;

剪刀石头布游戏

game of scissors, paper, stone

例句:

市场时机的选择就是一场庞大的“剪刀、石头、布”游戏。

Market timing is a giant game of scissors, paper, stone

 
友情链接
鄂ICP备19019357号-22