Help calling information out of an array.

Hey Guys how's it going. I need help with arrays. I need to store all sine values from 0 - 90 into an array. So I made an array the size of 200 since the sine values would only reach 180. But I do not know how to make the user input an angle and have the program call into the array and look for that angle and display the results. I've looked online and cant seem to find how to do this. It just shows how to display all the information which I do not need to do.

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
#include <iostream>
#include <math.h>

using namespace std;


int main ()
{
	double a;
	double data [200];
	double pi = acos(-1.0);
	cout << "Enter the angle to recive the sine value:\n";
	cin >> a;
	double x[200];
	for(int i = 0; i<=90; i++)
	{
		double x = i * pi / 180;
		double y =sin(x);
		cin >> data [i];
		cout << i << "\t" << y << "\n";
	}
	

	system("pause");
	return 0;
}


How do I call the information I need out of the array?
You could simply calculate the sine every time, when the user gives an angle.

However, your task is to create a lookup table, i.e. precalculate and store sine for several angles.

You do say that you want the table for angles 0-90. Integer values?

Array has indices. Integer values. The index of first array element is 0. The index of 91st array element is 90.

Replace the lines 19-20 with statement that stores the sine value (y) calculated from angle (i) into the ith element in the array (data).

Lines 12-13 do not belong into the precalculation phase. Your program would ask for an angle somewhere around line 23.
Topic archived. No new replies allowed.