/* this program wants to calculate the sum of the square roots of i*i - 10*i + 23 for all values of i over a certain range. It wants to avoid trying to calculate the square root of a negative, not only printing an error message if one is encountered, but also returning -1 as the whole value of the sum, as a second signal that something isn't right. This version does not succeed at all of its goals. */ #include "library.h" double f(const double i) { const double s = i*i - 10*i + 23; if (s < 0) { print("Error - square root of negative: "); print(s); print(" when i = "); print(i); new_line(); return -1; } return sqrt(s); } double sum(const int from, const int to) { if (from <= to) return f(from) + sum(from + 1, to); else return 0; } void main() { print(sum(0, 10)); new_line(); }