Advertisements

Stefan Ram wrote:
> To check whether it is correct, one needs to
> compare its actual behavior with the specification
> for its required behavior.

To the OP:

To expand on this a bit, what is your algorithm supposed to do when X is
negative? Obviously, you display "X cannot be negative" and stop, but
was that the required behavior? What if in the case of negative number
input the algorithm was really supposed to make X positive, take the
square root, then display "Ri" to signify an imaginary number? (R =
square root.)

So, your algorithm is probably correct, but you do need to get the idea
down of a specification. Please make sure to tell us first what the
algorithm is supposed to do, then give us an implementation to check.

It's like those problems in geometry where you're "Given X, Y, Z, show
that A is true." Then show the work. You've just shown us the work, we
aren't sure what you were given to do.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!