I have to take a 2d array of [6][8] floats that represent a star map and add the four surrounding numbers to it to measure it's intensity of light. Would something like make sense???

for(i=0;i<6;i++)
  {   
for(j=0;j<8;j++)
  {
stars[i][j+1] + stars[i+1][j] + stars[i-1][j] + stars[i][j-1];}}

instead of writing many lines of this type of code:

stars[1][1] = stars[1][1] + stars[0][1] + stars[2][1] + stars[1][0] + stars[1][2]

Also, I'm reading in the array from a text file with all integers, the array is declared and initialized as 0.0. When I add the numbers in the four surrounding spaces for one position as a test, I get 33 which is the correct answer. When I try to divide that number by 5.0 to get an integer, I get 28.2 instead of 6.6. I tried doing

(float)stars[i][j]

after reading in the int values from the file, but to no avail.

Any suggestions on that?

thanks.

I have to take a 2d array of [6][8] floats that represent a star map and add the four surrounding numbers to it to measure it's intensity of light. Would something like make sense???

for(i=0;i<6;i++)
  {   
for(j=0;j<8;j++)
  {
stars[i][j+1] + stars[i+1][j] + stars[i-1][j] + stars[i][j-1];}}

instead of writing many lines of this type of code:

stars[1][1] = stars[1][1] + stars[0][1] + stars[2][1] + stars[1][0] + stars[1][2]

Also, I'm reading in the array from a text file with all integers, the array is declared and initialized as 0.0. When I add the numbers in the four surrounding spaces for one position as a test, I get 33 which is the correct answer. When I try to divide that number by 5.0 to get an integer, I get 28.2 instead of 6.6. I tried doing

(float)stars[i][j]

after reading in the int values from the file, but to no avail.

Any suggestions on that?

thanks.

Well, if you can do a loop instead of hard-coding, that is definitely better. However, this:

for(i=0;i<6;i++)
  {   
for(j=0;j<8;j++)
  {
stars[i][j+1] + stars[i+1][j] + stars[i-1][j] + stars[i][j-1];}}

does nothing. All you are doing is adding a bunch of numbers together, but then doing nothing with the result. There is no assignment of a value to a variable.

I have to take a 2d array of [6][8] floats that represent a star map and add the four surrounding numbers to it to measure it's intensity of light. Would something like make sense???

for(i=0;i<6;i++)
  {   
for(j=0;j<8;j++)
  {
stars[i][j+1] + stars[i+1][j] + stars[i-1][j] + stars[i][j-1];}}

instead of writing many lines of this type of code:

stars[1][1] = stars[1][1] + stars[0][1] + stars[2][1] + stars[1][0] + stars[1][2]

Yes, the loops are better. Just format them correctly.

Also, I'm reading in the array from a text file with all integers, the array is declared and initialized as 0.0. When I add the numbers in the four surrounding spaces for one position as a test, I get 33 which is the correct answer. When I try to divide that number by 5.0 to get an integer, I get 28.2 instead of 6.6. I tried doing

(float)stars[i][j]

after reading in the int values from the file, but to no avail.

Any suggestions on that?

Yes. Give us the information we need to understand the problem. Code, values, etc...

Well the basic idea is to make a 2d array of numbers that represent stars size [20][20] and add up all of the numbers with their four surrounding "intensities." The array will get these 400 numbers from a text file and will output a text file ascii picture of a star map. I need to ignore the outer stars [0], 19, [0], [19] and just focus on the inner ones while doing the actual adding. The outer rows will be factored into the calculations though.

this is the psudo code I have to work with

(Array(i,j) + sum of the four surrounding intensities / 5 > 6.0

If the added number is greater then 6.0, I need to display a * and if it isn't, a blank line. So I'm thinking of making a parallel 2d array of the same value to build up as I add the stars. Maybe an if/then/else statement within a do while loop???

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.