#include <bits/stdc++.h>
using namespace std;


double evaluate(double x) {
    return x * x * x - 4.0;
}

int main() {
    double prev, curr, next, f_prev, f_curr, f_next, tolerance = 0.0001, approxRoot;
    int iteration = 0;

    cout << "Enter two initial guesses: ";
    cin >> prev >> curr;

    f_prev = evaluate(prev);
    f_curr = evaluate(curr);

    cout << "f(x1) = " << f_prev << ", f(x2) = " << f_curr << endl;

    
    next = (f_curr * prev - f_prev * curr) / (f_curr - f_prev);

    cout << "Iter\tNext\t\tPrev\t\tCurr\t\tf(Next)\tf(Prev)\tf(Curr)\n";
    cout << iteration << "\t" << fixed << setprecision(8)
         << next << "\t" << prev << "\t" << curr << "\t"
         << evaluate(next) << "\t" << f_prev << "\t" << f_curr << endl;

    while (true) {
        f_prev = evaluate(prev);
        f_curr = evaluate(curr);
        next = (f_curr * prev - f_prev * curr) / (f_curr - f_prev);
        f_next = evaluate(next);

        iteration++;
        cout << iteration << "\t" << fixed << setprecision(8)
             << next << "\t" << prev << "\t" << curr << "\t"
             << f_next << "\t" << f_prev << "\t" << f_curr << endl;

        if (fabs((next - curr) / next) < tolerance || iteration > 8)
            break;

        prev = curr;
        curr = next;

        approxRoot = next;
    }

    cout << fixed << setprecision(8);
    cout << "Approximate root = " << approxRoot << endl;

    return 0;
}
