compiling cosine function from any integer input

For my assignment I need to write a function outside of a main that outputs a min, max for 4 arrays and produces cosine of an angle inputted to system.
The min and max have ran successfully but to calc. cosine using only +,-.*,/ is proven difficult to do.

So for cosine I want to input a number say 405 and get the cosine from that angle or rather cosine of 45(405-360) and compare that cosine value to the value given using cmath. My value - cmath value = difference. Converting from radians to degrees I understand is necessary before able to make comparison.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 #include "stdafx.h" #include "char_plotting.h" #include #include #include double index(); int AR_SIZE; int i (0); using namespace std; double min (double index[],int AR_SIZE) // function to find minimum { int i = 0; // variable is declared inside function double min = AR_SIZE; for (i; i < AR_SIZE; i++) { if (min > index[i]) min = index[i]; } return min; } double max (double index[], int AR_SIZE) // func for max ------ { int i = 0; // declare i at first data entry double max = 0; for (i; i < AR_SIZE; i++) //declare, limit; and what it does { if (max < index[i]) max = index[i]; } return max; } double cos140 (double index[], int AR_SIZE) { double pi = 3.14159265; double deg = 0; double cos140 = 0; double rad = 180*deg/pi; int sign = 1; int fact = 1; double power_x = 0; int i, k = 0; // k is an even number double x = 0.7854; // that's radians--same as 45 degrees int counter = 0; cos140 = ((cos140 + sign * power_x) / fact); while (k < 20) { k = k + 2; // calculate the next even 1number fact = fact * (k -1) * k; // calculate the next factorial //cout << fact << endl; sign = sign * (-1); // calculate the next sign //cout << sign << endl; power_x = power_x * x * x; // calculate the next power of x //cout << power_x << endl; counter ++; cos140 = (cos140 + sign * power_x) / fact; //cout << cos140 << endl; } // add for cosine funct. -----------------// return cos140; // } int _tmain(int argc, _TCHAR* argv[]) //main { double tmin, tmax, cosG = 0; tmin = min (test1, TEST_SIZE); tmax = max (test1, TEST_SIZE); cout << "Buck's minimum of test1 is "<< tmin << endl; cout << "maximum of test1 is "<< tmax << endl; tmin = min (test2, TEST_SIZE); tmax = max (test2, TEST_SIZE); cout << endl << "Their minimum in test2 "<< tmin << endl; cout << "Its maximum for test2 "<< tmax << endl; tmin = min (test3, TEST_SIZE); tmax = max (test3, TEST_SIZE); cout << endl << "Our minimum found in test3 "<< tmin << endl; cout << "The maximum by test3 "<< tmax << endl; tmin = min (test4, TEST_SIZE); tmax = max (test4, TEST_SIZE); cout << endl << "Your minimum out of test4 "<< tmin << endl; cout << "My maximum by test4 "<< tmax << endl; int i = 0; cin>> "enter in degrees to be cosined" >> i; cout << i<< endl; return 0; }

This is what I have so far. Far from running. The cosine function was given to me and should approximate close enough.
a lot of errors.. First I declared cos140 function as I did with max and min functions however I am not using the arrays to call the function but to use an int inputted by user. My syntax sux here. What should be a more appropriate function declaration for what I am trying to do?
Topic archived. No new replies allowed.