请问这个C++程序怎么编?

来源:百度知道 编辑:UC知道 时间:2024/06/30 08:12:58
编写程序模拟石头、剪子、布游戏,规则是石头砸剪子,剪子剪布,布包石头。程序先随机生成石头、剪子、布中的一个,然后询问用户选择石头、剪子、布中的哪一个,并判断输赢,接着,询问用户是继续玩游戏还是结束游戏,如果用户选择继续,则重复刚才的操作,否则,程序结束。要求在程序结束前输出用户与计算机的输赢比例

最好能注明一下关键的步骤都在做什么,谢谢

#include <iostream>
#include <string>
#include <time.h>

using namespace std;

int winner(int p1,int p2){//判断胜负的函数
if(p1==p2)
return 0;
if(p1-p2==1 || p1-2==p2)
return 1;
return -1;
}

int main(){
int hisChoice,yourChoice,yourWins=0,hisWins=0;
string another;
do
{
system("cls"); //清一下屏幕
srand( (unsigned)time( NULL ) ); //电脑的选择随机生成
hisChoice=rand()%2;
cout<<"\"0\" means rock"<<endl<<"\"1\" means cissors"<<endl<<"\"2\" means paper"<<endl<<"Your choice is:"<<endl;
cin>>yourChoice;
if(yourChoice>2){ //大于2~~~作弊!呵呵
cout<<"You are cheating!"<<endl<<"Press any key to exit.";
system("pause>null");