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
- How can a quadratic roots function return error codes?ComputerScienceOne · Error Handling By Design
- How can enumerated types be used for error codes in C?ComputerScienceOne · Using Enumerated Types for Error Codes
- What kinds of user input can cause problems in a quadratic-roots program?ComputerScienceOne · Computing Quadratic Roots
- How can quadratic-equation inputs be provided as command-line arguments?ComputerScienceOne · Computing Quadratic Roots
- How can a C program compute the roots of a quadratic equation?ComputerScienceOne · Computing Quadratic Roots
- How does PHP compute the roots of a quadratic equation?ComputerScienceOne · Computing Quadratic Roots