Program "QuadForm"


Purpose: Given a quadratic equation of the form , this program uses the quadratic formula to solve for x. Also the "If" command is introduced as a logic test.


We've learned that when a quadratic cannot be factored, we can use the quadratic formula to find the two possible roots. What if the equation has no roots? Here we can apply the "If" command to test whether or not it has roots. Examine the equation.

and

The first step for our program so far, and the first step for this one, is to get input from the user. What needs to be input? Prompt the user for these values.

Think algorithmically, what is the first step to finding values for x? When working with the quadratic formula on paper, first you substitute a, b, and c into the equation and apply the order of operations. Evaluate the radicand first. Is it postive or negative? How does this affect the solution?

The quantity is known as the discriminant. The discriminant determines how many real roots the equation has. If the discriminant is greater than zero, there are two real roots. If the discriminant equals zero, there is one real root. If the discriminant is negative, there are no real roots. At this point we are only concerned with the real roots, so we must determine if it has any before calculating them.

Using the input (variables A, B, C) command the calculator to evaluate the discriminant and store it, preferably as D. Access the "If" command under the "program control" menu.

Think: if the discriminant is negative, then there are no real solutions. Let's test this and output a message to the user. If D<O, then display "no real roots." To access mathematical symbols such as greater than, less than, equals, etc. press the yellow "2nd" button followed by the "MATH" button (1st column, 3rd row). This is the "test" menu. Use "Then" under in "program control" to tell the calculator what to do when D is less than zero. To see an example of what you should have by now (variations are welcome, as long as they function correctly), click here.

For every time the discriminant is NOT less than zero, we would go ahead and calculate the roots. Use the "ELSE" command under the "program control" menu to signify any time D is greater than or equal to zero.

Type an expression the calculator can evaluate for when the numerator of the quadratic formula is the sum and store as a variable. Do the same for when the numerator is the difference.

Now you are ready for output. Display a short message and the variable in which you have stored your roots. For the rest of my program, click here. You can also take this opportunity to write a quick program to calculate the axis of symmetry of a quadratic. To see mine, click here.


For more explanation of the uses of "IF," click here.


RETURN to Intro/Program List.