小学生趣味C++编程第22课 抽奖

小学生c++编程资料

链接:https://pan.baidu.com/s/1XlA5AcjDXz5YWOFT32gSmw 
提取码:9iz9 

#include<iostream>
#include<ctime>      //需要调用time()函数 
#include<cstdlib>    //需要调用srand()和rand()函数
using namespace std;
int main()
{
  int n,a;
  cout<<"抽奖程序"<<endl;
  cout<<"请输入1-5:";
  cin>>n;
  srand(time(0));  //随机种子
  a=rand()%5+1;  //随机产生1至5的整数
  if(n==a)
    cout<<"恭喜您,中奖了!奖金10元"<<endl;
  else
    cout<<"没中奖,请付费2元" <<endl;
  cout<<"中奖号码是"<<a<<endl;
  return  0;
} 

  

猜你喜欢

转载自www.cnblogs.com/kixiaoyuan/p/12694997.html
今日推荐