回 帖 发 新 帖 刷新版面

主题:如何做到输入正确后,程序运行后结束?用实题请教!

[size=4][color=0000FF]我想做到以下效果:
身份证只能输入3次,超出3次后程序结束(即输入了非15位的身份证号时允许有3次输入的机会);而在3次以内,输入的身份证号满足15位,从而判断男或女并且程序结束(即不要再出现输入身份证号)!请帮忙修改![em18]
(附判断男女的规则定为:15位身份证的最后一个数是奇数就是男,是偶数就是女。)[/color][/size] 

[size=3][color=008000]CLS
PRINT "输入您的姓名:"
INPUT m$
PRINT "您的姓名是:"; m$
PRINT
PRINT "输入您的身份证号码(15位,共有3次机会),让我猜猜你的性别:"
FOR I = 1 TO 3
 INPUT sfz$
 IF LEN(sfz$) = 15 AND VAL(RIGHT$(sfz$, 1)) / 2 = FIX(VAL(RIGHT$(sfz$, 1)) / 2) THEN PRINT "您的性别是:女", "我猜得很准哟!"
 IF LEN(sfz$) = 15 AND VAL(RIGHT$(sfz$, 1)) / 2 <> FIX(VAL(RIGHT$(sfz$, 1)) / 2) THEN PRINT "您的性别是:男", "我猜得很准哟!"
 IF LEN(sfz$) <> 15 THEN PRINT "您输入的身份证号有错误!"
NEXT I
 PRINT "您居然忘记了自己的身份证号,那还有谁能猜出你的性别了!"
END[/color][/size]

回复列表 (共16个回复)

沙发


[em14]有点难,讲一下思路

板凳

不错不错

3 楼

CLS
PRINT "输入您的姓名:"
INPUT m$
PRINT "您的姓名是:";m$
PRINT
PRINT "输入您的身份证号码(15位,共有3次机会),让我猜猜你的性别:"
FOR I = 1 TO 3
 INPUT sfz$
 IF LEN(sfz$) = 15 AND VAL(RIGHT$(sfz$, 1)) / 2 = FIX(VAL(RIGHT$(sfz$, 1)) / 2) THEN PRINT "您的性别是:女, 我猜得很准哟!"
 IF LEN(sfz$) = 15 AND VAL(RIGHT$(sfz$, 1)) / 2 <> FIX(VAL(RIGHT$(sfz$, 1)) / 2) THEN PRINT "您的性别是:男, 我猜得很准哟!"
 IF LEN(sfz$) <> 15 THEN PRINT "您输入的身份证号有错误!您居然忘记了自己的身份证号,那还有谁能猜出你的性别了!"
NEXT I
END 


这样好些,你的程序有些小问题

4 楼

是的

5 楼

3楼、4楼请看清我的要求!并请在您的qbasic中试运行!谢谢!

6 楼

Extravagance to an honest beauty [b][url=http://www.game4power.com]Buy wow gold[/url][/b]orc was having a [url=http://www.aionkina.com]aion gold[/url]permanent place to live with [url=http://www.cheapaion.com][b]Aion Kina[/b][/url]at all. They had been nomads or prisoners for [b][url=http://www.game4power.com/buy-gold/]buy cheap wow gold[/url][/b]so long that the concept of “home” had been all [url=http://www.game4power.com/]buy gold wow[/url]but lost. Several of the massive, greenish figures tilled a [url=http://www.gold4power.com]cheapest wow gold[/url]field. Watching the tusked, brutish-looking workers, Krasus marveled at [url=http://www.bestwarhammer.com]buy warhammer gold[/url]the concept of orc farmers. Thrall, however[url=http://www.metin2sale.com]metin2 yang[/url] send off its power, was a [url=http://www.aionshopping.com]aion gold[/url]highly unusual orc and he had readilygrasped the ideas that would return [url=http://www.aionkinavip.com]aion kina[/url]stability to his people. Stability was something the entire world needed [url=http://www.gold4power.com]wow gold for sale[/url]badly. With another[url=http://www.aion4gold.com]aion gold[/url]wave of his hand, the dragon mage dismissed [url=http://www.gold4power.com]wow gold cheap[/url]Kalimdor, summoning now a much closer location—the once [url=http://www.itemchannel.com]world of warcraft gold[/url]proud capital of his favored Dalaran. Ruled by the wizards of the Kirin Tor, the prime wielders of magic for [url=http://www.cheapaion.com]cheap aion kina[/url], it had been at the forefront of the Alliance's battle against[url=http://www.game4power.com/]Wow Gold [/url]the BurningLegion[url=http://www.game4power.com/]www.game4power.com[/url] in Lordaeron and one of the first and most prized targets of the demons on[url=http://www.cheapaion.com][b]aion kina[/b][/url] in turn.

7 楼

楼上什么意思

8 楼

乱发哦~

9 楼

CLS
PRINT "输入您的姓名:"
INPUT m$
PRINT "您的姓名是:";m$
PRINT
10:PRINT "输入您的身份证号码(15位,共有3次机会),让我猜猜你的性别:"sfz$;
IF n=3 THEN PRINT“输入的身份证号有错误!您居然忘记了自己的身份证号,那还有谁能猜出你的性别了!”:END
IF LEN(sfz$)<>15 OR LEN(sfz$)<>18 THEN GOTO 10 :n=n+1
IF LEN(sfz$)=15 THEN
IF VAL(RIGHT$(sfz$,1)) MOD 2 =0 THEN PRINT "您的性别是:女, 我猜得很准哟!"
IF VAL(RIGHT$(sfz$,1)) MOD 2=1  THEN PRINT "您的性别是:男, 我猜得很准哟!"
ELSE
IF VAL(MID$(sfz$, 17,1)) MOD 2=0  THEN PRINT "您的性别是:女, 我猜得很准哟!"
IF VAL(MID$(sfz$, 17,1)) MOD 2=1  THEN PRINT "您的性别是:男, 我猜得很准哟!"
END IF
END
现在很多都是18位数,我又加了一个判断18位数的语句!

10 楼

楼上,一般用FOR不用GOTO吧!

我来回复

您尚未登录,请登录后再回复。点此登录或注册