例3:大乐透中奖查询
Label1.Text =
""
;
Label1.Text =
"
开奖号码是
:"
;
Label2.Text =
""
;
Label2.Text =
"
彩票号码是:
"
;
Label3.Text =
""
;
Label4.Text =
""
;
Label4.Text =
"
你中奖的号码是
:"
;
int
[] jianghao = { 1, 3, 8, 9, 12};
int
[] lanhao1 = {8,12};
int
[] caipiao = { 3, 5, 9, 12, 18};
int
[] lanhao2 = {8,10};
int
c = 0;
int
sum1= 0;
int
sum2 = 0;
//
显示开奖号码
foreach
(
int
a
in
jianghao)
{
Label1.Text += a.ToString() +
" "
;
}
foreach
(
int
b
in
lanhao1)
{
Label1.Text +=b.ToString()+
" "
;
}
//
显示彩票号码
while
(c< caipiao.Length)
{
Label2.Text += caipiao[c] +
" "
;
c++;
}
foreach
(
int
d
in
lanhao2)
{
Label2.Text +=d.ToString()+
" "
;
}
//
显示中奖情况(中奖号码及其个数)
for
(
int
i = 0; i < caipiao.Length; i++)
{
for
(
int
j = 0; j < jianghao.Length; j++)
{
if
(caipiao[i] == jianghao[j])
{
sum1++;
Label4.Text += jianghao[j] +
" "
;
}
}
}
for
(
int
f = 0;f< lanhao1.Length; f++)
{
for
(
int
g = 0; g < lanhao2.Length; g++)
{
if
(lanhao1[f] ==lanhao2[g])
{
sum2++;
Label4.Text +=lanhao1[f] +
" "
;
}
}
}
Label3.Text =
"
你中了
"
+ (sum1+sum2).ToString() +
"
个号码
"
;
//
根据中奖号码个数,判断中奖情况
if
(sum2 == 7)
{
Label5.Text =
"
恭喜你!中奖
500
万!
"
;
}
else
if
((sum1+sum2)== 6)
if
(sum1==6)
{
Label5.Text =
"
恭喜你!中奖
10
万!
"
;
}
else
{
Label5.Text =
"
恭喜你!中奖
3
万!
"
;
}
else
if
((sum1 + sum2) == 5)
if
(sum1==5)
{
Label5.Text =
"
恭喜你!中奖
1
万!
"
;
}
else
if
(sum1 == 4&&sum2==1)
{
Label5.Text =
"
恭喜你!中奖
3000
千!
"
;
}
else
{
Label5.Text =
"
恭喜你!中奖
200
百!
"
;
}
else
if
((sum1 + sum2) ==4)
if
(sum1==4)
{
Label5.Text =
"
恭喜你!中奖
200
百!
"
;
}
else
{
Label5.Text =
"
恭喜你!中奖
10
元!
"
;
}
else
if
((sum1 + sum2) == 3)
{
Label5.Text =
"
恭喜你!中奖
5
元!
"
;
}
else
{
Label5.Text =
"
谢谢再次光临!
"
;
}
本文出自 “刘文斌” 博客,谢绝转载!