基本版的(闪烁的频率是一秒闪一次,有点慢)
#include <iostream>
#include <string.h>
#include <cstdlib>//包含rand()的头文件
#include <ctime>//包含time()的头文件
#include <conio.h>//包含kbhit()函数
using namespace std;
int rand_number()
{
srand(time(NULL));//time(NULL)返回的是一个数值,是从1970年1月1日开始,一直到现在(系统时间)所经历的秒数,
return rand();
}
int main()
{
string a[3]={"a","b","c"};
int i;
while(true)
{
system("cls");//调用系统的控制台指令,“cls”是清屏指令,“pause”是系统暂停指令
i=rand_number()%3;//随机数对3取余就可以取得,0,1,2,这三个数字
cout<<"中奖的人是:"<<a[i]<<endl;
if(kbhit()) break;//判断是否有按键动作,如果有,返回true
}
system("pause");
return 0;
}
升级版的
#include <iostream>
#include <string.h>
#include <cstdlib>//包含rand()的头文件
#include <ctime>//包含time()的头文件
#include <conio.h>//包含kbhit()函数
using namespace std;
int rand_number()
{
return rand();
}
int main()
{
string a[3]={"a","b","c"};
int i;
srand(time(NULL));//将此语句放于循环语句之前,人名闪烁的就会很快
while(true)
{
system("cls");//调用系统的控制台指令,“cls”是清屏指令,“pause”是系统暂停指令
i=rand_number()%3;//随机数对3取余就可以取得,0,1,2,这三个数字
cout<<"中奖的人是:"<<a[i]<<endl;
if(kbhit()) break;//判断是否有按键动作,如果有,返回true
}
system("pause");
return 0;
}