抽学号的小程序

本文展示了一个使用C++编写的程序,演示了如何隐藏控制台光标并实现随机抽奖功能,结果显示中奖者编号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;


void hide_cursor()//隐藏光标
{
	HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cursor_info;
	GetConsoleCursorInfo(h_GAME,&cursor_info);
	cursor_info.bVisible=false;
	SetConsoleCursorInfo(h_GAME,&cursor_info);
}


int main()
{
	hide_cursor();
	int num=0,xytx[5];
	system("color 0f");
	cout<<"抽几名“幸运”的同学?";
	cin>>num;
	srand(unsigned(time(0)));
	
	for(int i=1;i<=num;i++)
	{
		system("cls");
		for(int j=1;j<=30;j++)
		{
			cout<<rand()%40+1;
			Sleep(1);
			system("cls");
		}
		do{
			xytx[i]=rand()%40+1;
		}
		while(xytx[i]==8||xytx[i]==37);
		cout<<xytx[i];
		Sleep(2000);
	}
	system("cls");
	cout<<"恭喜以下同学获得爬黑板的机会:\n";
	for(int i=1;i<=num;i++)
	{
		cout<<xytx[i]<<"号同学   ";
	}
	system("pause");
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值