clear;
clc;

f = @(x) (cos(x) + 1 - x);

x0 = input("Enter lower boundary: ");
x1 = input("Enter upper boundary: ");
accuracy = 0.001;

while (f(x0) * f(x1) > 0)
    x0 = input("Enter lower boundary: ");
    x1 = input("Enter upper boundary: ");
end

itr = 0;
while true
    itr = itr + 1;

    x = x1 - ((f(x1) * (x1 - x0)) / (f(x1) - f(x0)));
    y = f(x);

    if abs(y) <= accuracy
        break;
    elseif y*f(x0) < 0
        x1 = x;
    else
        x0 = x;
    end
end

disp("Value of x: " + x);
disp("Iteration: " + itr);