Using an array in a calculation

Using an array in a calculation, accessing the array with variables then being able to use it for
(r3+r4)/(r1+r2+r3+r4)
this is not working code , I don't understand why.

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
 	int main()
	{
		 input();
		//input function to remove variables in global scope, ignore
	
		double data[26] = { 0, 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7,
			5.6, 6.8, 8.2, 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82,
			100 };
		return 0;
		
		int i;
		
		double gain = (data[i] + data[i]) / (data[i] + data[i] + data[i] + data[i]);
		
		i = 0;
		while (i < 26) {
			cout << data[i] << endl;
			i++; //i+1
		}

		for (double r1 = data[i]; r1 < 26; r1++){ 
		}
			
		

		

		cin.ignore(); //to pause cmd but not working
			

	return 0;
	}
Last edited on
Well, for starters, your main returns on line 9, closing the program.
Right fixed,
closed account (48T7M4Gy)
See what happens if you delete line 9 !
closed account (48T7M4Gy)
You also need to initialize int i. This is a case where, if you don't, because it is undefined you are trying to access the array at an undefined position in line 13. i could be anything and yet it has to be in the range of 0 to 25!
Topic archived. No new replies allowed.