I'm working on a problem that says to write a program that accepts from the keyboard 3 numbers a, b, c which are the coefficients of the quadratic equation ax^2 +bx+c=0. Then, to make sure that:
1. b^2-4ac >=0
2. a does not equal zero
3. b^2 is not significantly > 4ac.
or else the program stops.
Otherwise, it outputs the real roots of the quadratic equation. I have, I believe, a program that does that just fine. However, another requirement is that there be absolutely minimal computations. Specificially, "division by 2a twice is allowable, otherwise none." I can't figure out how to possibly do that. Maybe a switch function? Anyway, here's the program I have that does the basics of the problem:
pow (b,2) - 4*a*c and b*b - 4*a*c together, 3 times
But first - you need to attend to the out-of-sequence processing. You can't bake the cake until you've bought the ingredients. Thus the calculations at lines 10 and 11 cannot be done until some time after the user supplies the input values at line 13. ... and it's probably better to postpone those calculations until after the other checks have been done as well.
The only minor complication in your example is the last condition,
3. b^2 is not significantly > 4ac.
which is similar to the discriminant, but not the same. Personally I'd just go ahead and calculate that separately, though you might find a clever way to store the b*b and 4*a*c in their own variables to avoid recalculation. Perhaps try it with and without that refinement.