生成随机数

    xiaoxiao2021-03-25  142

    #include <bits/stdc++.h> using namespace std; int main() { char t=1;///判断是否结束循环 while(1)///死循环 { int left; ///左边界 int right; ///右边界 cout<<"请输入您需要的左右边界:\n"; cin>>left>>right; if(left>=right) { cout<<"您的是输入数据不合法,请重新输入.\n"; continue; } srand( (unsigned)time(NULL) ); /// 截取毫秒 int num=rand()%right + left; ///对右边界取余 极爱左边界 while(!(num>= left && num<=right)) ///循环判断随机数在范围内 { srand( (unsigned)time(NULL) ); } cout<<"幸运听众的编号 "<<num<<endl; cout<<"是否继续运行?1:0\n"; ///吃回车 cin>>t; if(t=='0') { cout<<"欢迎下次使用!\n"; break; } else if(t=='1');///继续 else { cout<<"孙子你找死啊!!!!!"<<endl; break; } } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-8975.html

    最新回复(0)