win10家庭版 dpi设置:if 语句的问题

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 22:47:15
题目详细:
给出性别及年龄,对应输出以下的信息:

男 8岁以下 小弟弟
8岁到15岁 小男孩
16岁到24岁 小伙子
25岁到45岁 青年男子
46岁到55岁 中年男子
56岁到80岁 老爷爷
81岁以上 老寿星
女 8岁以下 小妹妹
8岁到15岁 小女孩
16岁到24岁 小姑娘
25岁到45岁 青年女子
46岁到55岁 中年女子
56岁到80岁 奶奶
81岁以上 老奶奶

答案:

dim sex,age
sex="男"
age=50
if sex="男" then
if age<8 then
response.Write("小弟弟")
else
if age>=8 and age<=15 then
response.Write("小男孩")
else
if age>=16 and age<=24 then
response.Write("小伙子")
else
if age>=25 and age<=45 then
response.Write("青年男子")
else
if age>=46 and age<=55 then
response.Write("中年男子")
else
if age>=56 and age<=80 then
response.Write("老爷爷")
else
if age>80 then response.Write("老寿星")
end if
end if
end if
end if
end if
end if
else
if age<8 then
response.Write("小妹妹")
else
if age>=8 and age<=15 then
response.Write("小女孩")
else
if age>=16 and age<=24 then
response.Write("小姑娘")
else
if age>=25 and age<=45 then
response.Write("青年女子")
else
if age>=46 and age<=55 then
response.Write("中年女子")
else
if age>=56 and age<=80 then
response.Write("奶奶")
else
if age>80 then response.Write("老奶奶")
end if
end if
end if
end if
end if
end if
end if
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
问题1:上面的IF 开头是8个下面怎么是6个为什么是正确的?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if sex="男" then
if age<8 then
response.Write("小弟弟")
else
if age>=8 and age<=15 then
response.Write("小男孩")
else
if age>=16 and age<=24 then
response.Write("小伙子")
else
if age>=25 and age<=45 then
response.Write("青年男子")
else
if age>=46 and age<=55 then
response.Write("中年男子")
else
if age>=56 and age<=80 then
response.Write("老爷爷")
else
if age>80 then response.Write("老寿星")
end if
end if
end if
end if
end if
end if
这里是不是一组IF语句?如果是,为什么是上8开,下6结束那
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if age>80 then response.Write("老寿星")
if一行写完是不需要end if的

。。这个就是关于缩进的问题,因为程序是开始分成两大类(男、女)然后再每类来分年龄段,如果你用缩进来写程序,就再清晰不过了,我写给你看
if sex="男" then
if age<8 then
response.Write("小弟弟")
else
if age>=8 and age<=15 then
response.Write("小男孩")
end if
else
if age<8 then
response.Write("小妹妹")
else
if age>=16 and age<=24 then
response.Write("小姑娘")
end if
end if

这回清楚了吧?