Help with Array

I'm trying to build a population for my Genetic Algorithm Project using an array. The number of the population is 10 and it consists of 28 binary bit. Here is my code:

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

using namespace std;

int main(){
	
	float binary [10][28];
	float population_bin [10][29];
	float population_dec [10][29];
	int row, column;
	
// Binary convertor//
	for (row = 1; row <= 10; row ++){
		for (column = 0; column <= 27; column ++){
			binary [row][column] = pow (2, column);
			}
	}
	
//Binary Population//
	for (row = 1; row <= 10; row ++){
		for (column = 0; column <= 27; column ++){
			population_bin [row][column] = rand ()% 2;
			} 
	}
	
//Binary Conversion into Decimal//
	for (row = 1; row <= 10; row ++){
		for (column = 0; column <= 27; column ++){
			population_dec [row][column] = binary [row][column] * population_bin [row][column];
		}
	}
	
//Population Decoder//
	float A, B;
	for (row = 1; row <= 10; row ++){
		A = 0;
		B = 0;
		for (column = 0; column <= 27; column ++){
			A += population_dec [row][column];
			B = 20 + (A*0.0000744313004405472);
		}
		cout << "Population Number " << row << " is " << B << endl;
	}

			
	getch ();
	return 0;
}


And the results are as follows:


Population Number 1 is 5746.61
Population Number 2 is 17959.6
Population Number 3 is 4246.73
Population Number 4 is 16603.9
Population Number 5 is 18836.4
Population Number 6 is 18333
Population Number 7 is 18365
Population Number 8 is 14957
Population Number 9 is 3034.82
Population Number 10 is nan


Why is Population Number 10 resulted in "nan"??
Array indices starts at 0, so row should go from 0 to 9 instead of 1 to 10.
So my code should be like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	float binary [10][28];
	float population_bin [10][28];
	float population_dec [10][28];
	int row, column;

for (row = 0; row <= 10; row ++){
A = 0;
B = 0;
for (column = 0; column <= 27; column ++){
A += population_dec [row][column];
B = 20 + (A*0.0000744313004405472);
}
cout << "Population Number " << (row+1) << " is " << B << endl;
}
As was said for an array of size N subscripts shall be in the range [ 0, N - 1]. So this code is invalid

1
2
3
4
5
6
7
 	float population_dec [10][28];
	int row, column;

for (row = 0; row <= 10; row ++){
A = 0;
B = 0;
for (column = 0; column <= 27; column ++){
Okey dokey!! Thanks everyone!
Topic archived. No new replies allowed.