The program only successfully asks for the size of the cell, then prints out the error.
Here's my code so far:
#include <iostream>
using namespace std;
const int MAX_SIZE = 100;
// function prototypes
void initialize_array(char array[MAX_SIZE][MAX_SIZE], int size);
// prototype for function to output the array
// prototype for function to grow the array
bool is_alive(char array[MAX_SIZE][MAX_SIZE], int size, int row, int col);
// prototype for function to count the number of live neighbors of cell(i,j)
int main()
{
// declare variables, including array to hold cell array
int n, k, x, y;
char A[100][100];
// ask for cell array size
cout << "Enter the size of the cell: ";
cin >> n;
// check that cell array size is within minimum and maximum bounds
// if not, persistently ask for cell array size
// until number is within bounds
while (n < 5 || n > 100) {
cout << "Cell size must be between 5 and 100."<<endl;
cout << "Re-enter cell size";
cin >> n;
}
// initialize_array(array, size);
for (int p=1; p<= n*n; p++) {
A[p-1][p-1] = '.';
}
// ask for number of seeds
cout << "Input number of seeds:";
cin >> k;
// ask for row and column of each seed
// check that row and column is within the cell array
// if not, persistently ask for the row and column
// until row and column are within the cell array
// set the cell at the given row and column to '*' (baby)
for (int s=1; s<= k; s++) {
cout <<"Enter row and column for seed "<<s;
cin >>y;
cin >>x;
if (y<0 || y>n-1 || x<0 || x>n-1) {
while (y<0 || y>n-1 || x<0 || x>n-1) {
cout << "coordinates are out side of specified array."<<endl;
cout << "Re-enter row and columb of seed "<<s;
cin >>y;
cin >>x;
}
}
else {
A[y][x] = '*';
}
}
// call the function to output the initial array
for (int row=0; row<n; row++) {
for (int col=0; col<n; col++) {
cout << A[row][col] << " ";
}
cout << endl;
}
Sorry if the comments get in the way, they were in the starter file we were given.
Also if you see any other problems besides the immediate please tell me, thanks.

New Topic/Question
This topic is locked




MultiQuote






|