Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

First year programming yay!

Name: Anonymous 2008-03-01 21:22

Hola /prog/,

I'm attempting to write the code for Conway's Game of Life for my C++ class (out of '.' '*' and '@') Everything compiles fine, yet it doesn't do what I want. I've been pouring over the damn thing, and I thought you guys might be kind enough to help out.

Where i is the row, t is column, M is the array storing the number of live cells. I think the problem is in what I've posted here, or the functions, which I will post in a second. When I run this all it does is output the original grid of cells, even though my functions should have changed them in SOME way.

 for (int i = 1; i <= n; i++)
    {
      for (int t = 1; t <= n; t++)
    {
      M[i][t] = count(A, n, i, t);
    }
    }

  for (int x = 0; x >= steps; x++)
     {
      grow(A, M, n, i, t);
     }
   output_array(A, n);

Name: Anonymous 2008-03-01 21:24

The aforementioned functions. They are all prototyped and everything is declared properly.

//Live cells function.

bool is_alive(char array[MAX_SIZE][MAX_SIZE], int size, int row, int col)
{
  if (row < 0 || row >= size || col < 0 || col >= size)
    { return false; }
  else if (array[row][col] == '.')
    { return false; }
  else
    { return true; }
}

//Count function.

int count(char array[MAX_SIZE][MAX_SIZE], int size, int row, int col)
{
  int lives;

   for (row = row-1; row == row+1; row++)
    {
      for (col = col-1; col == col+1; col++)
    {
      if (is_alive(array, size, row, col) == true)
        {
          lives = lives + 1;
        }
    }
    }
      return lives;
}

//Growth function.

void grow(char array[MAX_SIZE][MAX_SIZE], int M[MAX_SIZE][MAX_SIZE], int size, int row, int col)
    {
    for (row = 1; row <= size; row++)
      {
        for (col = 1; col <= size; col++)
          {
        array[row][col] == '@';
        if (array[row][col] == '.' && M[row][col] == 3)
          {
            array[row][col] = '*';
          }
        else if (M[row][col] == 0 || M[row][col] >= 4)
          {
            array[row][col] = '.';
          }
          }
      }
     

Name: Anonymous 2008-03-01 21:30

It's because you have a shitty indentation style.

Name: Anonymous 2008-03-01 21:36

It was better before copy paste, but a valid point none the less! I'll go check that.

Name: Anonymous 2008-03-01 21:37

Oh, and your count function is broken. Check the for conditions.

Name: Anonymous 2008-03-01 21:37

>>It was better before copy paste
Use the [code] tag, my son.

Name: Anonymous 2008-03-01 21:42

>>It was better before copy paste
Use the [code] tag, my son.

Use shiichan quoting, my son.

Name: Anonymous 2008-03-01 21:44

I don't see the problem in the for conditions.

Name: Anonymous 2008-03-01 21:51

TURNS OUT IT WASN'T THE INDENTATION.

Name: Anonymous 2008-03-01 22:04

>>1
Does not scale .__.

Name: Anonymous 2008-03-01 22:05

>>8
   for (row = row-1; row == row+1; row++)
    {
      for (col = col-1; col == col+1; col++)

Name: Anonymous 2008-03-01 22:11

>>11

What do you recommend I do? I tried changing to limits to +2?

Name: Anonymous 2008-03-01 22:12

>>12
Try thinking about what that code does. It will never run. And if it would, it wouldn't terminate anyway.

Name: Anonymous 2008-03-01 22:35

Shouldn't it evaluate from the given row-1 until row+2? The function's intent is to check the eight cells around one.
(around the center cell, which would be (row, col))
...
...
...

Wouldn't putting that function in this loop

for (int i = 1; i <= n; i++)
    {
      for (int t = 1; t <= n; t++)
    {
      M[i][t] = count(A, n, i, t);
    }
    }

be kosher?

Name: Anonymous 2008-03-01 22:37

for (row = row-1; row == row+1; row++)
{
    /*..*/
}

is

row = row-1;

while(row == row+1)
{
    /* ... */
    row++;
}


What do you expect to happen?

Name: Anonymous 2008-03-01 22:43

>>15

I don't expect anything to happen I guess. I feel like I need to nix a variable out of there or possibly write the function differently altogether.

Name: Anonymous 2008-03-01 22:48

>>16
Re-write the whole thing.

Name: Anonymous 2008-03-01 22:52

All you have to do is use an extra variable:

int foo;[br][br]for(foo = row - 1; foo <= row + 1; foo++)

Name: Anonymous 2008-03-01 22:52

int foo;

for(foo = row - 1; foo <= row + 1; foo++)


Ugh.

Name: Anonymous 2008-03-01 23:31

I tried all of this, and the shit still doesn't work. Sigh.

Name: Anonymous 2008-03-01 23:35

It's not the only problem. For example, array indexes start at 0, not 1.

Name: Anonymous 2008-03-01 23:38

for (int x = 0; x >= steps; x++)

Won't work either. Post the code you have now.

Name: Anonymous 2008-03-02 2:04

I realized the array's started at 0 a while back, but for all intents and purposes I didn't think it would make that much of a difference while I was doing the actual coding. I plan on fixing it once there is some kind of effective output.

>>22 Why won't that work? It seems like it makes sense to me.

Name: Anonymous 2008-03-02 2:11

>>23
It will likely crash, because you're also reading/writing outside of the end of the array. See http://en.wikipedia.org/wiki/Off-by-one_error.

It will not work because steps is an integer larger than 0, and x >= steps will initially (always) be false. The condition should be x < steps.

Remember that the second condition in the for statement must be true at all times in order for the for loop to execute its body.

Name: Anonymous 2008-03-02 2:14

This thread makes me sad. Anons helping each other (which are either trolls or the dumbest person alive). /prog/ is dead.

Name: Anonymous 2008-03-02 2:22

>>25
................................I$7?Z7?=~+?7ZI+=,...............................
............................,?$D=~~?~~~~~~~~~~~~~+77............................
.........................=?+~~~Z=~~~~~~~~~~~~~~~~~~~~+7.........................
.................. ,+??7~~~~~~~7=~~~~~~~~~~~~~~~~~~~~~~~7~......................
...............~7.=:~~~~~~~~~~~7~~~~~~~~~~~~~~~~~~~~~~~~~~7:....................
............I=..,:~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~:Z ..................
.........==..,.I..~~~~~~~~~~~~~~~~~~$=~~~~~~~~~~~~~~~~~~~~~~~7??+,..............
.......+~=?=,~.,....,~~~~~~~~~=~$=~~++~~~~7~~~~~~~~~~~++~~~~~$~~~$..............
.....~$+,...?.,.,.:.....:~~~=O~~7~~~+?~~~~~$~~~~~~~~~~~~7~~~~Z=~~II=............
...,=......7.,...,.....,~:~~~~~~==~~~.8.,:::$~~~~:,,,....$~~~7~~~~~I7...........
..........Z,:~~~~+~~~~=7~~~=Z~~~.$~~:.,I~=~::I.,..,,..,..,$II+~~~~~~~M..........
.........Z=~~~~~O=~~~=Z~~~~~~~~+:.=~~=,:7~~~~OZ=~:,,.....,,:,?~~~~~~~I..........
........O~~~~~?7~~~~=+~~~=~I~~I:,,I~~7,,:$~~~~7?==~~~~~~+~:,~?~~~:~~~=..........
......,+~~~~~?$I~~~~?$~~~~7D=Z~$,,,O=7,,::7~+=$+?+~~~~~~~+~~=$~~~~~~~=..........
......=~~~~:$.D~~~~+I:~~~~~+:.,,,,,,+=.:,,::=~+8IOO=~~~~~=?=~~Z~~~~=~~..........
......=~~=$.,.~~~~?+Z~~~~~$+Z,,,,,,:~~$,,,,,.I=I,.OZ~~~~~~???~:$~~~~~~..........
....,Z~=?~...I~~~+?+~~~~~I.+.,,,,,,,,Z7.,,,,,,I~~,,II~~~~~=+$$==:+~~~~..........
.....~~7.....Z~~~??I~~~~~,.8::,,:,,,,,$$,,:,,,.O$,,.,I~~~~~++?Z:Z7~~~~..........
....8I.......=~~???Z~~~~MMMDNZ~+?:,,,,,O,,,,=?.,ONMMNNNM7~~~+ZI?~:~~:=..........
....7.......=~~++??8~~~Z,=:.,ODMM?,:,,:,$:::,MMNIZZZZ,NN=~~~?8?=?Z=?~+..........
...O........$=~??+DO~~Z,,O~.,ZZZ8O::,,,,,,,:$,.,.ZZZZ:D,O=~~=$?~=O~$~I..........
............O=???878~~Z.,=+O$Z$Z$.,,,,,,,,,,,,O$+ZZ$$..:~7~~~?+~~~+O~$..........
............$~??O?IO~O:Z:,:OZZO+,,,,,,,,,,,,:.ZIZO7OZ,,::7+=~??~~~~==Z..........
............I+?O,~?O=.:?,,.D+~=:8,,,,,,,,,,,,~$:=~=Z,:,,,,=+~+=~~~$~~Z..........
............+?O.+~?$D::.,,:?Z~:ZN,,,,,,,,,,,,,ZI~~ZZ.,,,,,,+~+~~~~8~?Z..........
............+?..O+??O.,:?::,88Z+,,,,,,,,,,,,,,~I8N8$:,,,,,,,O==~~:7~IZ..........
............+8..$????I=,$:::::::,,,,,,,,,,,,,,,:::,::,,,,,,:.+~~~?+~$Z..........
............?...+???=?+I8::::::,,,,,,,,,,,,,,,,:::::::,,,,,:OZ~~~O?~$$..........
............M...:??+=???7,:::::,,,,,,,,,,,,,,,::::::::7,8$O+~~~~~??~$$..........
...............I~??+?=???7:::::,,,,,,:=,,,,,,,,,::,:?...?=?=~~~~$+?=$$..........
...............O+???Z=???Z?7I~.,,,,,I+=,,,,,,,,,~?,....O?O+~~~~~7??=7$..........
...............7+???Z~~?~Z?+Z.,?$~:Z7.,,,,,::$=,.....,,?I?~:~~=$+??+?$..........
..............:~????$~~~:Z??Z......+:~DII?+~~=........8+7=:~~~=I?????7..........
..............I~+????~~~,$??$......+~.O======$?.......I8~,~~~~D?????=7..........
..............Z=????+~=~:=+?$.,OI=I~7++=========IO$+:+Z~:~~~~?Z?????:Z..........
..............$+?????I~~~~??77,~ODZ$N$88$++~==~++?~+:O~:=~~~:?Z?????=N..........
..............I????+7O~~~~Z?7+.+..,..,....~?77?===:,,$:~~~~~Z?Z?????+M..........
..............+?+??+ZI:~~,$+Z,......,......~=+=:,,,,Z:=~~~~7I?O+?????D..........
..............~?????Z?=~~~=I=7,.,~+?I++:.,.OZOOZ+,,.+:~~~=ZO??O??????7..........
..............~+????I?8=~~:O?O,:...,..,....O==I$=O.8:~~~=7..??$+?????=..........
..............=????++?,=~~~=7O:~......77...:,,,,=OZ~~~~:?.,,O?7??????+..........
.............,=??????Z,O~~~~87I=.....?+7+,:$7,,ZI.~~~~~=,,,,8??7?????+..........
.............,++?????$,.~~~+,,,,Z,,.,Z?++,:,,77I~8~~~=~7,,,,O?+$?????+,.........
..............++???+O.,,Z~~?,,:,7$:..=8.,,,,:,O.,:~~~:~,,,,,O?+$?+???+~.........
..............++???8,,,:.I=:,,,,O77$O+.7,,,,,,+,O=~~~+:,,,,,7+?8??????+.........
..............++?+Z.,,,,,,=~:,,,7$7$O7Z$,,,,:,7,~~~~O:,,,,,,,O?O???????.........
..............I???+:,,,,,,I7:,,,8777OO7Z,,:,,:,8:~~I.,,,,,,,,.?I+??????.........
..............$???I,,,,,,,$,,,::$7$$7O$$Z7Z+,,::++=:,,,,,,,,,,7?+?????+.........
.............,8?+?I~:,,,,O:,,,NZ$$$$Z8$$77OZ:,,,,,O.,,,,,,,,,,.8+?????,.........
..............+?????~~=,O:,,,:7~~$Z$D8$ZI.?.=,,,,,,,+?,,,,,,,.8?+?????..........
...............7++++~,,..,,,,,,Z7.......+7Z.+,,,,,,,.7,,I,,,,Z+?++++++..........

Name: Konata 2008-03-02 2:49

>>26

CAN'T CENSOR OUR LOVE

Name: Anonymous 2008-03-02 3:04

READ K&R

Name: Anonymous 2008-03-02 3:32

ENYOU YOUR SEPPLES

Name: Anonymous 2008-03-02 4:16

>>,
DON'T HELP HIM!!

Name: Anonymous 2008-03-02 14:40

Help him. DEFINITELY NOT OP.

Name: Anonymous 2008-03-02 15:25

OP here, my tutor found out about this page, now hes accusing me of plagarism. Thanks a bunch.

Name: Anonymous 2008-03-02 15:42

>>32
I lol'd.

Name: Anonymous 2008-03-02 16:00

>>32
Fucking owned. That's what you get for posting Anonymously.

Next time learn to use a goddamn debugger and work the fucking logic errors yourself instead of coming here and bothering us with your stupid fucking Sepples problem. Help yourself, thus help us, and we will help you in return (by raping you up the ass with beautiful Konata ASCII art she is my waifu bampu pantsu etc).

NOW GET THE FUCK OUT

Name: Anonymous 2008-03-02 16:49

>>34
gtfo weeaboo faggot.

Name: Anonymous 2008-03-02 17:57

>>34
Never mind, I fixed it myself.

Name: Anonymous 2008-03-02 18:01

>>35
Welcome to 4chan faggot

Name: Anonymous 2008-03-02 18:18

>>34
Too bad it's actually Kagamin~~

>>35
WHO'S THE WEEABOO NOW, FAGGOT?

Name: Anonymous 2008-03-02 18:21

Name: Anonymous 2008-03-02 23:36

lol it's the same mistake every makes when writing that

Name: Gracious OP 2008-03-03 2:31

I got it done, /prog/. I thank you for your words of wisdom, as well as your scorn.

Name: Anonymous 2009-10-12 20:58

[#]
[m][sup]
        [i]e[/i]   [b][i][o][u]S u s s[/u][/o][/i][/b]                 
      [i]h[/i]             [b][i][o][u]m[/u] [/o][/i][/b]              
    [i]t[/i]    [b][o][u]O R N A D[/u][/o][/b]    [b][i][o][u]a[/u][/o][/i][/b]             
       [b][o][u]T[/u][/o][/b]           [b][o][u]O[/u][/o][/b]    [b][i][o][u]n[/u][/o][/i][/b]           
 [i]d[/i]           [b]m y[/b]                     
[i]n[/i]    [b]e[/b]   [i]h[/i]        [o][u][i][b]W[/b][/i][/u][/o]   [i]o[/i]   [i]s[/i]          
[i]A[/i]   [b]h[/b]   [i]t[/i]         [o][u][i][b]A[/b][/i][/u][/o]   [i]f[/i]   [i]a[/i]          
    [b]t[/b]   [i]i[/i]    “    [o][u][i][b]N[/b][/i][/u][/o]       [i]i[/i]          
        [i]w[/i]      [i]![/i] [o][u][i][b]D[/b][/i][/u][/o]    [b][i]B[/i][/b]   [i]d[/i]          
                     [b][i]B[/i][/b]                 
     [spoiler]e[/spoiler]    [b][i]E[/i][/b]             "            
       [spoiler]r[/spoiler]    [b][i]D O C[/i][/b]     [b]I[/b]              
         [spoiler]u[/spoiler]                         
           [spoiler]j n o c[/spoiler]                 
[/sup][/m]
[/#]

Name: Anonymous 2009-10-12 20:59

[m][#]
[m][sup]
        [i]e[/i]   [b][i][o][u]S u s s[/u][/o][/i][/b]                 
      [i]h[/i]             [b][i][o][u]m[/u] [/o][/i][/b]              
    [i]t[/i]    [b][o][u]O R N A D[/u][/o][/b]    [b][i][o][u]a[/u][/o][/i][/b]             
       [b][o][u]T[/u][/o][/b]           [b][o][u]O[/u][/o][/b]    [b][i][o][u]n[/u][/o][/i][/b]           
 [i]d[/i]           [b]m y[/b]                     
[i]n[/i]    [b]e[/b]   [i]h[/i]        [o][u][i][b]W[/b][/i][/u][/o]   [i]o[/i]   [i]s[/i]          
[i]A[/i]   [b]h[/b]   [i]t[/i]         [o][u][i][b]A[/b][/i][/u][/o]   [i]f[/i]   [i]a[/i]          
    [b]t[/b]   [i]i[/i]    “    [o][u][i][b]N[/b][/i][/u][/o]       [i]i[/i]          
        [i]w[/i]      [i]![/i] [o][u][i][b]D[/b][/i][/u][/o]    [b][i]B[/i][/b]   [i]d[/i]          
                     [b][i]B[/i][/b]                 
     [spoiler]e[/spoiler]    [b][i]E[/i][/b]             "            
       [spoiler]r[/spoiler]    [b][i]D O C[/i][/b]     [b]I[/b]              
         [spoiler]u[/spoiler]                         
           [spoiler]j n o c[/spoiler]                 
[/sup][/m]
[/#][/m]

Name: Anonymous 2011-01-31 21:24

<-- check em dubz

Don't change these.
Name: Email:
Entire Thread Thread List