三角有效性 [英] Triangle Validity

查看:63
本文介绍了三角有效性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Puhleeeease检查这个.......

没有给出正确的输出...

展开 | 选择 | 换行 | 行号

解决方案

嵌套如果语句是OR条件。


如果你的三角形是a = 10,则b = 4和c = 5:


然后a< (b + c)是假的。这是一个无效的三角形。然而, else 继续检查b< (c + a)这是真的。所以你的程序显示三角形是有效的。


一旦检测到无效的三角形,你的程序应该停止而不能继续。


有各种方法来编写这个,我把它留给你。



Puhleeeease检查这个


为了什么?不要给我们一个代码转储并让我们找到错误。我们可以在我们自己的代码上进行错误搜索,谢谢。提出一个真实的问题。


没有给出正确的输出...



所以也许你应该编程它以提供正确的输出。如果您不再向我们提供不正确的详细信息,那么我们不会给您任何更好的回复,而不是使其正确。


请详细说明。你观察到了什么?你尝试了什么?你把问题缩小到哪里了?不要在没有信息的情况下将工作转移给我们。


编辑:作为提示,尝试更明确地使用括号。它清楚地表明了代码块是什么。在if / else一个衬里中尤其如此,当没有大括号嵌套时,可能会让人感到困惑。你不知道还有什么比得上。


你可能还想用英语/数学告诉我们你认为你正在解决的算法。我几乎可以保证到目前为止发布的所有专家/ mod都知道用于检测有效三角形的算法,但是根据你发布的内容还不清楚你是否

  1. 知道算法检测有效三角形但是实现不正确
  2. 不知道算法检测有效三角形但是已经实现了你认为应该正确的算法
  3. 不知道检测有效三角形的算法,但是已经实现了你认为应该是但算法不正确的算法



在你之前笑我在商业项目中看到c都发生在一个稍微复杂的算法上。


Puhleeeease check this .......
Isnt giving the correct output ...

Expand|Select|Wrap|Line Numbers

解决方案

Nested if statements are an OR condition.

If your triangle is a= 10, b= 4 and c = 5:

then a < (b+c) is false. This is an invalid triangle. However the else goes onto to check b < (c+a) which is true. And so your program displays that the triangle is valid.

Once you have detected an invalid triangle, your program should stop and not continue on.

There are various ways to code this and I leave that up to you.


Puhleeeease check this

For what? Don''t give us a code dump and set us off with "find the errors". We can do bug hunting on our own code, thanks. Ask a real question.

Isnt giving the correct output ...

So maybe you should program it to give the correct output. If you don''t give us anymore details than "it is not correct", than we won''t give you a response any better than "make it correct".

Details please. What do you observe? What did you try? Where did you narrow the problem down to? Don''t dump work on us with little information.

EDIT: As a hint, try to use braces more explicitly. It makes it clear what the blocks of code are. This is especially true in if/else one liners, which when nested without the braces can become confusing to read. You don''t know what else matches to what if.


You may also wish to tell us, in English/Maths, the algorithm you think you are solving. I can pretty much guarantee that all the experts/mods that have posted so far know the algorithm for detecting a valid triangle but from what you have posted it is not clear if you

  1. Know the algorithm to detect a valid triangle but have implemented it incorrectly
  2. Do not know the algorithm to detect a valid triangle but have implemented the algorithm you think it should be correctly
  3. Do not know the algorithm to detect a valid triangle but have implemented the algorithm you think it should be but implemented that incorrectly


And before you laugh I have seen c happen in commercial projects all be it on a slightly more complex algorithm.


这篇关于三角有效性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆