抽奖代码制作(抽奖代码制作教程)
admin 发布:2022-12-19 23:21 139
本篇文章给大家谈谈抽奖代码制作,以及抽奖代码制作教程对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、用c语言编写一个简易的抽奖程序,
- 2、抽奖程序(用vb编写)
- 3、怎么用vb做一个抽奖程序
- 4、C语言程序设计——编写一个抽奖程序,生成0-9之间的随机数,猜对了奖励10块钱,没中奖显示中奖号码
- 5、VB编程年会抽奖代码?
- 6、求一份抽奖游戏(Java写的代码)
用c语言编写一个简易的抽奖程序,
用data.txt文件保存以下内容:
13725528132 李桂荣
13725528131 李二来
13725528133 张荣刚
13725528130 荣南
13725528137 王三
13725528138 吴立
13725528139 郭德纲
13725528140 周星驰
13725528141 张曼玉
13725528142 张艺谋
13725528152 秦香莲
13725528162 潘金莲
13725528172 李大嘴
13725528182 展堂
//源代码如下
#include stdio.h
#include stdlib.h
#include time.h
#define MAX_NUM 9999
//定义保存人名和电话的数据结构
struct Person
{
char name[20];
char telno[15];
char award;
};
int num = 0; //统计人数
FILE *fp; //文件指针
Person persons[MAX_NUM]; //定义数组
int awarder_1[1] = {-1}; //一等奖
int awarder_2[2] = {-1, -1}; //二等奖
int awarder_3[5] = {-1, -1, -1, -1, -1};//三等奖
//读取文件
void readdata()
{
int i = 0; //数组下标
Person person;
//文件打开
fp = fopen("data.txt", "r");
if (fp == NULL)
{
printf("打开文件data.txt失败!\n");
return;
}
//当文件不为空
while (!feof(fp))
{
num ++;
fscanf(fp, "%s", person.telno);
fscanf(fp, "%s", person.name);
person.award = 'F';
persons[i++] = person;
}
}
//初始化标识
void init()
{
for(int i = 0; i num; i++)
{
persons[i].award = 'F';
}
}
//显示单个中奖信息
void info( int i)
{
printf("手机号码: %s 姓名: %s\n", persons[i].telno, persons[i].name);
}
void main()
{
char again = 'Y';
//读取文件
readdata();
printf("简单抽奖程序\n");
srand((long)time(0));
while(again == 'Y' || again == 'y')
{
//初始化标识
init();
printf("\n开始抽第一等奖(1名),按任意键开始...\n");
getchar();
awarder_1[0] = abs(rand() % num);
while (persons[awarder_1[0]].award == 'T')
{
awarder_1[0] = rand() % num;
}
persons[awarder_1[0]].award = 'T';
info(awarder_1[0]);
printf("\n开始抽第二等奖(2名)\n");
for (int i = 0; i 2; i++)
{
printf("\n第%d个二等奖,按任意键开始...\n", i+1);
getchar();
awarder_2[i] = rand() % num;
while (persons[awarder_2[i]].award == 'T')
{
awarder_2[i] = rand() % num;
}
persons[awarder_2[i]].award = 'T';
info(awarder_2[i]);
}
printf("\n\n开始抽第三等奖(5名)\n");
for (i = 0; i 5; i++)
{
printf("\n第%d个三等奖,按任意键开始...\n", i + 1);
getchar();
awarder_3[i] = rand() % num;
while (persons[awarder_3[i]].award == 'T')
{
awarder_3[i] = rand() % num;
}
persons[awarder_3[i]].award = 'T';
info(awarder_3[i]);
}
printf("\n是否重新开始抽奖?(Y or N)...\n");
again = getchar();
}
getchar();
return;
}
抽奖程序(用vb编写)
在窗体上添加一个command1,一个timer1,label1(0~5)
控件数组(添加一个label1,然后再复制5个,共6个,用来显示数字),代码如下:
Private
Sub
Command1_Click()
If
Command1.Caption
=
"抽奖"
Then
Command1.Caption
=
"停止"
Timer1.Enabled
=
True
Else
Timer1.Enabled
=
False
Command1.Caption
=
"抽奖"
End
If
End
Sub
Private
Sub
Form_Load()
Command1.Caption
=
"抽奖"
Timer1.Interval
=
50
Timer1.Enabled
=
False
End
Sub
Private
Sub
Timer1_Timer()
Randomize
For
i
=
To
5
Label1(i)
=
Int(10
*
Rnd)
Select
Case
Label1(i).Caption
Case
Label1(i).BackColor
=
RGB(0,
0,
0)
Label1(i).ForeColor
=
RGB(255,
255,
255)
Case
1
Label1(i).BackColor
=
RGB(128,
42,
42)
Label1(i).ForeColor
=
RGB(127,
213,
213)
Case
2
Label1(i).BackColor
=
RGB(255,
0,
0)
Label1(i).ForeColor
=
RGB(0,
255,
255)
Case
3
Label1(i).BackColor
=
RGB(255,
97,
0)
Label1(i).ForeColor
=
RGB(0,
158,
255)
Case
4
Label1(i).BackColor
=
RGB(255,
255,
0)
Label1(i).ForeColor
=
RGB(0,
0,
255)
Case
5
Label1(i).BackColor
=
RGB(0,
255,
0)
Label1(i).ForeColor
=
RGB(255,
0,
255)
Case
6
Label1(i).BackColor
=
RGB(0,
0,
255)
Label1(i).ForeColor
=
RGB(255,
0,
0)
Case
7
Label1(i).BackColor
=
RGB(160,
32,
240)
Label1(i).ForeColor
=
RGB(95,
223,
15)
Case
8
Label1(i).BackColor
=
RGB(192,
192,
192)
Label1(i).ForeColor
=
RGB(63,
63,
63)
Case
9
Label1(i).BackColor
=
RGB(255,
255,
255)
Label1(i).ForeColor
=
RGB(0,
0,
0)
End
Select
Next
End
Sub
怎么用vb做一个抽奖程序
只要在窗体中做二个命令按钮、一个标签和一个定时器对象,复制以下代码,就可以运行了:
Private Sub Command1_Click()
If Command1.Caption = "开始" Then
Command1.Caption = "暂停"
Timer1.Enabled = True
Else
Command1.Caption = "开始"
Timer1.Enabled = False
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Label1.Caption = ""
Label1.FontSize = 50
Timer1.Interval = 50
Timer1.Enabled = False
Command1.Caption = "开始"
Command2.Caption = "结束"
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Int(Rnd * 50) + 1
End Sub
C语言程序设计——编写一个抽奖程序,生成0-9之间的随机数,猜对了奖励10块钱,没中奖显示中奖号码
代码如下,已测试通过:
int main()
{
int no,ret;
printf("请输入你猜测的号码:\n");
scanf("%d",no);
ret=rand()%10;
printf("本次开奖结果=[%d]:\n",ret);
if(no==ret)
{
printf("恭喜你猜中了,中奖10元!\n");
}
else
{
printf("很遗憾,再来一次吧!\n");
}
return 0;
}
可以把上面代码改成多次输入,即将输入和取随机数都放在while循环中。自己修改下吧
VB编程年会抽奖代码?
语言实现此程序。
以下是VB编程语言的实现示例:
'定义变量,存储每个奖项的人数
Dim firstPrize As Integer = 3
Dim secondPrize As Integer = 5
Dim thirdPrize As Integer = 12
Dim souvenirPrize As Integer = 10
'定义变量,存储抽奖结果
Dim firstPrizeList As New List(Of Integer)
Dim secondPrizeList As New List(Of Integer)
Dim thirdPrizeList As New List(Of Integer)
Dim souvenirPrizeList As New List(Of Integer)
'定义变量,存储编号滚动的起始编号
Dim currentNum As Integer = 1
'循环抽取各种奖项
For i As Integer = 1 To firstPrize
'抽取一等奖,并将编号添加到一等奖名单中
firstPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To secondPrize
'抽取二等奖,并将编号添加到二等奖名单中
secondPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To thirdPrize
'抽取三等奖,并将编号添加到三等奖名单中
thirdPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To souvenirPrize
'抽取纪念奖,并将编号添加到纪念奖名单中
souvenirPrizeList.Add(currentNum)
currentNum += 1
Next
'输出抽奖结果
Console.WriteLine("一等奖名单:" String.Join(",", firstPrizeList))
Console.WriteLine("二等奖名单:" String.Join(",", secondPrizeList))
Console.WriteLine("三等奖名单:" String.Join(",", thirdPrizeList))
Console.WriteLine("纪念奖名单:" String.Join(",", souvenirPrizeList))
求一份抽奖游戏(Java写的代码)
import java.util.Scanner;
/**
*
*/
public class f {
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.print("请输入抽奖号码上限:");
int max = scan.nextInt();
System.out.print("请输入抽奖次数:");
int n = scan.nextInt();
System.out.print("中奖号码依次为:");
for(int i=0;in;i++){
System.out.print((int)(Math.random()*max+1)+" ");
}
}
}
关于抽奖代码制作和抽奖代码制作教程的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-15如何制作一个网页网站,如何制作一个网页?
- 05-15广西网站建设制作,广西网站建设制作公司
- 05-15免费开发软件制作平台,软件免费开发网站
- 05-14网站建设网站制作,网站建设制作免费
- 05-13怎么制作公司网页,怎样制作自己公司的网页
- 05-12网站制作免费,免费网址制作平台
- 05-11怎么在百度制作自己的网站,如何能在百度上设计个自己的网页
- 05-11廊坊网站,廊坊网站建设模块制作
- 05-09网页代码,网页代码快捷键
- 05-09网站免费制作,免费制作网站教程
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接