Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C program need help to slove this test case: neighbor(grid,0,0,3,0) incorrectly returns 1 however it needs to return 2 . My program is below please

C program need help to slove this test case: neighbor(grid,0,0,3,0) incorrectly returns 1 however it needs to return 2. My program is below please help. I believe my nested if statements does not check every neigbor.

/******************************************************************************

*******************************************************************************/

#include #define MAXSIZE 50 //Max size of NUM #define MAXTIME 50//Max size of time step size

int neighbors(int anArray[MAXSIZE][MAXSIZE][MAXTIME+1], int i, int j, int size, int step) //returning alive space at each time step { int valTot=0; //initilaizes valTot for temp counter

if(i>=0&&j>=0&&i=0) { if(anArray[i][j-1][step]==1) valTot++; if(i-1>=0) if(anArray[i-1][j-1][step]==1) valTot++; if(i+1=0) if(anArray[i-1][j+1][step]==1) valTot++; if(i+1=0){ if(anArray[i-1][j][step]==1) valTot++; if(i+1

// retuns printed grid array (size by size) void printGrid(int myGrid[MAXSIZE][MAXSIZE][MAXTIME+1],int size,int step) { int ver=0; int hor=0; while(ver

int main() //main call { int n=0; int i=0; int j=0; int ver=0; //sets ver and hor to 0 int hor=0; int setArray[MAXSIZE][MAXSIZE][MAXTIME+1]={0}; //setting and initialzing 3D array to '0' printf("Conway's game of Life "); printf("Please enter the n for the n x n grid to simulate, max size for n is 50. :"); scanf("%d",&n); // user entered input for size n if(n>50) { printf("ERROR "); return 0; } printf(" Enter the initial x y coordinates (the board is indexed starting from 0 0) for the initial live cells, enter -1 -1 when done "); while(ver!=-1||hor!=-1) // checking if user ends with -1 -1 { scanf("%d %d",&ver,&hor); if(ver>n-1) //checking if ver is bigger than dimentions of user input { printf("ERROR "); //printing error message when user enters number value outide scope return 0; } if(hor>n-1) //checking if hor is bigger than dimentions of user input { printf("ERROR "); return 0; } setArray[ver][hor][0]=1; } int genSet=0;//sets genSet=0 printf(" Please enter the number of time steps you wish to simulate, max number allowed is 50."); scanf("%d",&genSet); //taking user input for time steps printf("Num time steps %d ",genSet); //printing time step printf("After %d timesteps the grid is: ",genSet); int k=0; //setting counter to 0 while(k<=genSet) //calculating grid after user inputs timesteps { i=0; while(i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

ISBN: 0764549634, 9780764549632

More Books

Students also viewed these Databases questions