C++ 彩票器

#include <iostream>
#include <ctime>
#include <cstdlib> 
using namespace std;
int main(int argc, char** argv) {
  //1.获取一下你买的彩票号码
  int number=0;
  while(true){
    cout<<"请选择你要购买的彩票号码(1~10):";  
    cin>>number;
    if(number<1||number>10){
      cout<<"出票失败,请重新选择!"<<endl; 
    }else{
      break;
    }
  }  
  //2.生成本次中奖的号码
  srand(time(0));//种下一个随机种子 
  int ok=rand();  
  while(true){
    if(ok>0&&ok<11){
      break;
    }else{
      ok=rand();
    }
  }
  //3.对比是否中奖 
  if(number==ok){
    cout<<"恭喜恭喜!!!!你中奖啦!!!!";
  }else{
    cout<<"很遗憾,你没有中奖。本次中奖的号码是:"<<ok;
  } 
  return 0;
}

  

posted @ 2022-10-01 22:07  王一行  阅读(85)  评论(0)    收藏  举报