/// Geoff Hagopian computing cos(x)

#include "..\std_lib_facilities.h"

double cos(double);

int main() {
    double x;
    cout << "\nEnter a double and we'll compute its cosine. ";
    while(cin >> x) {
        cout << "\nThe cos(" << x << ") = " << cos(x);
    }
}

double cos(double t) {
    double term = 1;
    double accumulator = 1;
    double n = 2, nfactorial = 2;
    while(abs(term)> 0.0000001) {  ///rough and ready and needing improvement
        term *= -t*t;
        term /= nfactorial;
        accumulator += term;
        cout << "\nn = " << n/2 << "  term = " << term << " cos = " << accumulator;
        ++n;
        nfactorial *= n;
        ++n;
        nfactorial *= n;
        cout << "\nfactorial = " << nfactorial;
    }
    return accumulator;
}
