c++随机数的产生(game)

#include
#include
using namespace std;
int main()
{
    cout<<"**********************************"<<endl;
    cout<<"剪刀石头布游戏,s=剪刀,r=石头,p=布"<<endl;
    cout<<"请输入你的猜想"<<endl;
    srand((unsigned)time(NULL));
    char boss;
    int type;
    char changer;
    type=rand()%3;
    switch (type)
    {
    case 0:
        boss='s';
        cin>>changer;
        if(changer=='p')
        {
            cout<<"你赢了,电脑出的是剪刀"<<endl;
        }
        if(changer=='r')
        {
            cout<<"你输了,电脑出的是剪刀"<<endl;
        }
        if(changer=='s')
        {
            cout<<"你们打成了平手"<<endl;
        }
        break;
    case 1:
        boss='r';
                cin>>changer;
        if(changer=='s')
        {
            cout<<"你赢了,电脑出的是石头"<<endl;
        }
        if(changer=='p')
        {
            cout<<"你输了,电脑出的是石头"<<endl;
        }
        if(changer=='r')
        {
            cout<<"你们打成了平手"<<endl;
        }
        break;
    case 2:
        boss='p';
                cin>>changer;
        if(changer=='r')
        {
            cout<<"你赢了,电脑出的是布"<<endl;
        }
        if(changer=='s')
        {
            cout<<"你输了,电脑出的是布"<<endl;
        }
        if(changer=='p')
        {
            cout<<"你们打成了平手"<<endl;
        }
        break;
    default:
        break;
    }

}


你可能感兴趣的:(c++)