#include
#include
#include
#include
int main1(int n1)
{
srand((unsigned)time(0));
n1=rand()%3;
return n1;
}
int main()
{
int cho,good,temp,win=0,lose=0,tie=0;
char a;
cout<<"一一一一一一一一一一一一一一一一一一一一一一一一一一一一"<
while(1){
cout<<"//////////新一局//////////"<
cin>>cho; //用户输入1-3任意数
good=main1(temp);
switch (good)
{
case 0:
cout<<"对方出了剪子\n";
if (cho==1) cout<<"您赢了"<
case 1:
cout<<"对方出了石头\n";
if (cho==3) cout<<"您赢了"<
case 2:
cout<<"对方出了布\n";
if (cho==2) cout<<"您赢了"<
}}
return 0;
}
#include
#include
#include
#include
using namespace std;
int guess(void)
{
return rand() % 3;
}//end guess
int main(void)
{
//规则表。下标表示:0-石头,1-剪子,2-布;内容表示:0-平局;1-玩家胜;2-计算机胜
int rules[3][3] = {
{0, 1, 2},
{2, 0, 1},
{1, 2, 0}
};//end rules
char names[3][5] = {"石头", "剪子", "布"};
char results[3][20] = {"势均力敌!", "您赢了!", "您输了!"};
srand(time(0)); //初始化随机数
int cmd = 0, computer = 0, game = 0, games[3]={0, 0, 0};
cout << "----------------------\n欢迎进入石头剪子布小游戏世界!按任意键开始...\n----------------------" << endl;
for(;;) {
cout << "///////////新一局/////////\n0-出石头;\n1-出剪子;\n2-出布;\n其他任意键结束:\n*********************\n请选择" << endl;
cmd = getch() - '0';
computer = guess();
if(cmd<0 || cmd >2) break;
cout <<"您出的是:" << names[cmd] << endl;
cout <<"我出的是:" << names[game]<< endl;
game = rules[cmd][computer];
games[game]++;
cout << results[game]<< endl << endl;
cout << "战况:赢" << games[1] <<"次;输:" << games[2] << "平:"<< games[0] << "次" << endl;
}//next for
return 0;
}
运行结果与题目提供的样本截屏完全一致!!!采纳我的吧!楼上的没有计分这个功能!
#include
#include
#include
using namespace std;
int getIt()
{
srand((unsigned)time(NULL));
int n= rand()%3;
return n;
}
int main()
{
int a, n, win, lose, draw;
win=lose=draw=0;
cout << " /////////////新一局/////////////" <
{
n=getIt();
switch(n)
{
case 0:cout<<"对方出了剪子\n"; break;
case 1: cout<<"对方出了石头\n"; break;
case 2: cout<<"对方出了布\n"; break;
}
n++;
if(a == n) {
cout << "draw game " << endl;
draw++;
}
else if( a + 1 == n || (a==3 && n==1)) {
cout << "computer win" <
}
else {
cout <<"you win" <
}
cout <<"战况: 赢" << win <<"次; 输: "<< lose <<"次"<< " 平:" << draw << "次"<
return 0;
}
//楼上的也太不厚道了吧
孩子你是华东交大的吧?
给你发工程文件了,谢谢~~