乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 97|回复: 4

[编程交流] [lisp] Calculation not going r

[复制链接]

27

主题

113

帖子

90

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
132
发表于 2022-7-5 15:45:20 | 显示全部楼层 |阅读模式
Hi,
 
I'm trying to get an avarage height between 2 z-values.  However in the calculation part i get  a 'error: bad function: "11.30"' error (height of first point in this case).
 
As far as i can tell my calculation part seems to be right, but it won't seem to accept the value.
 
What is going wrong?
 
  1. (Defun c:zavg (/ punta puntb za zb tot avg)(setq punta (getpoint "\nKies het eerste punt"))(setq puntb (getpoint "\nKies het tweede punt"))(setq za (caddr (trans punta 1 0)) za (rtos za 2 2))(setq zb (caddr (trans puntb 1 0)) zb (rtos zb 2 2))(setq tot (+ za zb))(setq avg (/ tot 2))(princ avg))
回复

使用道具 举报

49

主题

177

帖子

130

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
243
发表于 2022-7-5 16:08:19 | 显示全部楼层
You are trying to add two strings! First do the math, then convert them to strings.
回复

使用道具 举报

27

主题

113

帖子

90

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
132
发表于 2022-7-5 16:20:14 | 显示全部楼层
Removing the rtos part seem to do the trick .
 
  1. (Defun c:zavg (/ punta puntb za zb tot avg)(setq punta (getpoint "\nKies het eerste punt:"))(setq puntb (getpoint "\nKies het tweede punt:\n"))(setq za (caddr (trans punta 1 0)))(setq zb (caddr (trans puntb 1 0)))(setq tot (+ za zb))(setq avg (/ tot 2))(acet-ui-status (strcat "Hoogte 1e punt: "(rtos za)"\nHoogte 2e punt: "(rtos zb)"\nDe gemiddelden hoogte is: " (rtos avg 2 2)) "Gemiddelde hoogte")(princ))
 
Thanks.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 16:30:50 | 显示全部楼层
Hi,
You did convert the variables (za & zb) to strings then you are trying to sum the two values and that is the error message that the program indicating to.
 
One solution:
  1. (setq tot (+ (distof za) (distof zb)))
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 16:47:52 | 显示全部楼层
Like others you used getpoint which is xyz and you want it as numbers so no Rtos, end result may need a rtos to make the (princ (strcat "average is " (rtos avg 2 2)))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 00:17 , Processed in 0.484561 second(s), 73 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表