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.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "stdafx.h"
#include "char_plotting.h"
#include <cmath>
#include <iostream>
#include <string>

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.