今天,用c++制作一个好玩的石头剪刀布玩玩(需要在dev-c++编译并运行,运行前关闭360,因为会误报)
首先,先写上c++大部分程序的标配
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
然后,写上using namespace std;
//头文件
using namespace std;
最后,就是整个最重要的东西——主要的代码
int main(){
int r,input_num;
cout<<"========石头剪刀布小游戏========";
string computer,person;
srand(time(0));
r = rand()%3+1;
switch(r){
case 1:computer="石头";break;
case 2:computer="剪刀";break;
case 3:computer="布";break;
}
cout<<"电脑已出拳"<<endl;
cout<<"请你出拳(1.石头 2.剪刀 3.布)"<<endl;
cin>>input_num;
switch(input_num){
case 1:person="石头";break;
case 2:person="剪刀";break;
case 3:person="布";break;
}
cout<<"电脑出的拳:"<<computer<<",你出的拳:"<<person<<endl;
if(input_num==r)
{
cout

这篇博客介绍了如何使用C++编程语言开发一款简单的石头剪刀布游戏。开发者详细阐述了代码实现过程,包括必备的C++语句和游戏逻辑,适合初学者实践。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



