Concept
How can conditionals handle invalid inputs and special cases in a quadratic roots program?
ComputerScienceOne / Quadratic Roots Revisited
"Let’s return to the quadratic roots program we previously designed that uses the quadratic equation to compute the roots of a quadratic polynomial by reading coefficients a, b, c in from the user. One of the problems we had previously identified is if the user enters “bad” input: if a = 0, we would end up dividing by zero; if b² − 4ac < 0 then we would have complex roots. With conditionals, we can now check for these issues and exit with an error message. Another potential case we might want to handle differently is when there is only one distinct root (b² − 4ac = 0). In that case, the quadratic formula simplifies to −b / 2a and we can print a different, more specific message to the user. The full program can be found in Code Sample"
Related Ideas
- How can conditionals handle invalid inputs and special cases in a quadratic roots program?ComputerScienceOne · Quadratic Roots Revisited
- How can conditionals handle invalid and special cases in a quadratic roots program?ComputerScienceOne · Quadratic Roots Revisited
- What topics are covered in Conditionals?ComputerScienceOne · Computing Quadratic Roots . . . . . . . . . . . . . . . . . . . . .
- How can conditionals calculate tax brackets, credits, and total tax?ComputerScienceOne · Quadratic Roots Revisited
- How can conditionals validate input for a logarithm calculator?ComputerScienceOne · Quadratic Roots Revisited