As the title said, I'm confused as to what I did wrong to get closed. I'm not irritated, either, I just want to know to improve myself; but from what I saw, it said to make the question easier to answer and also make the code as minimal as possible (which now I know it is because I use using namespace std
from the comment) but is that enough to get closed or is it something else? I want some constructive feedback, please.
-
7Minor but critical: the codes are missing results of running the code in textual format. Images should only be used for supporting the question, not replacing details that can be explained in the text. See also: Why should I not upload images of code/data/errors when asking a question?. This may also apply to some of your previous questions.– Andrew T.Commented Jun 11, 2022 at 4:50
-
1The post "does not show any research effort", which is not a reason to close but is a reason to downvote. Common sense suggests that research would even find a duplicate since it is a very simple question, and being a duplicate is a reason to close and the zillionth duplicate is "not useful" which is a reason to close. Clarify posts via edits, not comments. A close notice does not give the reasons for all votes cast.– philipxyCommented Jun 11, 2022 at 7:32
-
2It's not a question. You've just stated a few things and implied a question. Ask your question outright, don't beat around the bush. Easy downvote for this alone. The implied question itself is quite poor quality as well.– JK.Commented Jun 12, 2022 at 22:40
-
1Agreed that the closure was overzealous. Don't expect a question like this to do well on Stack Overflow though (especially not in tags for languages which have been around for decades, the bar will be set quite high for new questions). Questions that stem from "I've just started learning X today" should probably go to other sites that are more aimed at helping people who are completely unfamiliar with a subject. Just because Stack Overflow exists does not imply you can or should post all your questions there.– GimbyCommented Jun 13, 2022 at 14:58
2 Answers
I disagree with the closure reason of needs debugging details. There are two complete programs (formatted using appropriate markdown) which are complete and can easily be run to reproduce the behaviour described. One value rounds up to 3 and the other rounds down to 2, which doesn't quite follow the human understanding of numbers (2.4999999999999999999 < 2.5 so it should round down).
While it is true that there are also images of code and output (which are unnecessary and discouraged), that does not change the fact that the minimal necessary information is contained within the question in a useful format (appropriately formatted text).
Having said this, however, I do believe the other close vote which proposed a duplicate of Is floating point math broken? was likely correct as it explains the underlying cause.
There are many other examples on Stack Overflow. Here is one that may be more relevant (in python): Why round(1.4999999999999999) = 2?
-
3An MRE includes desired & actual output & giving it only in an image is not giving it.– philipxyCommented Jun 11, 2022 at 7:30
-
2I genuinely don't understand how this question does not include both as text. The last code block + "why it round up to 3" (actual) + "and not go back to 2" (desired/expected) is all the information necessary for a MRE and that is all in text. It does not matter that the information is also given in an image; it is given as text. This question's content is currently a superset of the required information for a MRE.– Henry Ecker ModCommented Jun 11, 2022 at 12:45
Here are some hints for asking better questions in the future:
Writing better prose and clear questions
Let's consider the original text of the question:
I have just started learning C++ today and learned about round(x) so I was just testing about it with .49999 because I'm curious how it would turn out and got confused between 2 of the results
I guessed that it couldn't go far beyond 16 decimals but I still don't understand why it round up to 3 and not go back to 2
The most glaring issue here is that this does not ask a question. While it is not a strict requirement, the best way to ask is to write something that can actually be considered a question - i.e., start with a question word like "why" or "how", and end with a question mark ("?"). Aside from that, the first sentence is a confusing run-on sentence, and the second lacks proper punctuation.
It's also hard to understand the description of the problem, because the wording is vague. Where you say, "I still don't understand why it round up to 3 and not go back to 2" - what is "it"? What do you mean by "going back to" 2 - in what sense was "it" "there" in the first place?
Instead, be precise with the claim:
but I still don't understand why the
round
function returns3
rather than2
for an input of2.4999999999999999999
.
Then, convert that to a question, by just pulling out the indirect question:
Why does the
round
function return3
rather than2
for an input of2.4999999999999999999
?
At this point we notice that the first part of the original, "I guessed that it couldn't go far beyond 16 decimals", is not useful and should be omitted entirely - it does not help to understand the problem. (It only makes the answerers wonder: why 16 decimals, instead of some other number? What is "it", and what does "going" mean here?)
The first sentence is useful context, but it should be several sentences. Our first draft would look like:
I have just started learning C++ today, and learned about round(x). I was just testing about it with .49999 because I'm curious how it would turn out. I got confused between 2 of the results
Let's fix up the grammar a bit and explain concepts more clearly:
I just started learning C++ today, and today I learned about the
round
function. I was testing it with numbers with a decimal part close to .5, because I wanted to see how it would turn out. I got confused by these two results:
This is not a discussion forum
It's hard to say this in a nice way, but: we don't care about your level of expertise, or about the path you have been taking to learn programming. These things do not help answer the question, and Stack Overflow is not about being a programmer, but about the code. If you are trying to become a better programmer, or chart out a path for yourself, actual discussion forum sites like Reddit or Quora are much better equipped to help you.
On Stack Overflow, we edit questions to remove noise. It's better if the asker does this in advance.
In this case, saying that the results are confusing is redundant - since we just finished fixing up the question, which is exactly about those results. You wouldn't be asking if you weren't confused. It normally isn't necessary to justify the fact that you were experimenting with some code - this is a natural thing to do. (There are times when people will ask you "why do you want to do this? What problem are you really trying to solve?", but IMHO it is better not to try to anticipate this.) And, again, it isn't necessary to mention how you discovered the round
function in the first place.
Putting the two pieces of text together, and re-editing with those hints in mind, we get something like:
I wrote these two pieces of code, to test the
round
function with numbers with a decimal part close to .5:
[code goes here]
Why does the
round
function return3
rather than2
for an input of2.4999999999999999999
?
State your Expectations
This version of the question probably looks quite barren. Most questions should be fairly sparse, but I agree that this version goes too far. There is one crucial piece of missing information here: the expected behaviour. Let's add that:
I wrote these two pieces of code, to test the
round
function with numbers with a decimal part close to .5:
[code goes here]
I expected that the output would be
2
in both cases, since.499999
is less than.5
even if there are many9
s. Why does theround
function return3
rather than2
for an input of2.4999999999999999999
?
As Noted, Avoid Images
Please allow me to add one more link to Why should I not upload images of code/data/errors when asking a question?. I agree that the original question had all the necessary information, because it had text in addition to the screenshots. However, the screenshots therefore redundant, and noisy. Many people who see screenshots will tune out immediately, and not notice the accompanying code.
Worse, the screenshot displayed the code (and output) in the opposite order from the formatted textual code - making it harder to talk about the examples. I initially wrote this post using phrases like "in the first case" and "in the second case", and then realized they would be ambiguous.
If you want to show program output, that should also be textual unless it is a GUI program. In this case, the output is small enough to show inline, as above. If you have multiple lines of input, please copy and paste from the terminal, and format it like code.
-
2Finally: be prepared to get the question closed as a duplicate anyway. It does happen sometimes. Pretty much every question along the lines of "why does this weird thing happen with floating-point numbers in this edge case?" is considered a duplicate, because the answer is essentially always the same: floating-point numbers have limited precision, and don't work by storing decimal digits. Commented Jun 13, 2022 at 23:13