你是不是也想知道自己的幸运值呢?
来试试看吧!
废话不多说,上代码!
不要忘记点赞哦~~~
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
void measureLuck(int l){
int n;
cout<<"输入测幸运次数吧!:";
cin>>n;
cout<<"最大的和是"<<n*9<<"呦"<<endl;
int y=1;
int z=0;
while(y<=n){
int x=rand()%10;
cout<<x;
if(y!=n){
cout<<"+";
}
y++;
z+=x;
}
cout<<"="<<z<<endl;
double s=n*9;
l=(z*100.0)/s;
cout<<"你的幸运值是"<<l<<"%呦!"<<endl;
}
int main(){
int c;
while(1){
cout<<"欢迎来到测幸运小程序!"<<endl;
cout<<"输入1,能测幸运呦"<<endl;
cout<<"输入2,能玩PK呦!"<<endl;
cin>>c;
if(c==1){
int l;
measureLuck(l);
}else if(c==2){
int l1,l2;
cout<<"玩家1,准备好了吗?"<<endl;
measureLuck(l1);
cout<<"玩家2,准备好了吗?"<<endl;
measureLuck(l2);
if(l1>l2){
cout<<"玩家1赢了!"<<endl;
}else if(l1<l2){
cout<<"玩家2赢了!"<<endl;
}else{
cout<<"平局呦!"<<endl;
}
}else{
cout<<"重新输入一下吧!"<<endl;
}
}
return 0;
}
标签:measureLuck,1.0,cout,int,c++,while,小游戏,幸运值,include
From: https://blog.csdn.net/c_c_csss/article/details/145166730