明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 898|回复: 2

[求助]为什么输出有错

[复制链接]
发表于 2008-10-13 10:19 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-10-13 10:20:17 编辑

请各位高手指教,程序怎么修改,先谢过了。

(defun c:mdnum()
    (setq num1 (getreal "\n Enter  first number:"))
    (setq num2 (getreal "\n Enter second number:"))
    (setq ans(strcase (getstring "enter M or D:")))
    (if (= ans "M")
      (setq x (* num1 num2))
    )
    (if (= ans "D")
      (setq x (/ num1 num2))
    )
    (if (and (/= ans "D") (/= ans "M"))
    (prompt "sorry!wrong entry, Try again")
    )
    (princ x)
    (Princ)
    )

以下是运行结果,错误出现在第三个方式:

命令:
MDNUM
 Enter  first number:10
 Enter second number:2
enter M or D:m
20.0
命令:(**********请教这行能否去掉啊)

命令:
MDNUM
 Enter  first number:10
 Enter second number:2
enter M or D:d
5.0
命令:(***********请教这行能否去掉啊)

命令:
MDNUM
 Enter  first number:10
 Enter second number:2
enter M or D:h
sorry!wrong entry, Try again5.0(******这个5.0怎么去掉啊)

发表于 2008-10-13 12:10 | 显示全部楼层

getstring用getkword替换会好点

要把5.0去掉,可以把

(if (and (/= ans "D") (/= ans "M"))
(prompt "sorry!wrong entry, Try again")
)
(princ x)

改成

(if (and (/= ans "D") (/= ans "M"))
(prompt "sorry!wrong entry, Try again")
(princ x)
)
   

 楼主| 发表于 2008-10-13 15:37 | 显示全部楼层

谢谢水手,已经试过了,第2个问题解决,第一个用getkword基本没有变化。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-6-2 01:12 , Processed in 0.344588 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表