Character Arrays and Numbers MineSweeper Problem

I'm currently working on an exercise that has you write a mock minesweeper program that wants you to use file input to create a Minesweeper board that displays the mine locations and the count for how many mines a non-mined tile it touching.

Below is my partially completed code. Currently I'm testing a 4x4 board from an input file in this format:

4 4
*...
....
.*..
....

However, my output at this point is just a bunch of characters, and I'm not sure how to address this.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 #include <iostream>
#include <fstream>
using namespace std;



//Global CONSTANTS
const int ROWS = 100,			// Program Specs given maximum number of rows for field
		  COLS = 100;			// Program specs given maximum number of columns for field



// Function prototypes
void testFile(ifstream &);
void boardSize(ifstream &, int &, int &);
void setBoard(ifstream &, int, int, char[][COLS]);
void formatBoard(int, int, char[][COLS], char[][COLS]);
void output();



int main(){

	// Open input and output files specified in program specs
	ifstream inputFile("inputdata.dat");
	ofstream outputFile("outputdata.dat");

	// Declare program variables
	int n = 0,						// Program Specs given variable for number of rows on field
		m = 0;						// Program Specs given variable for number of columns on field

	char inputField[ROWS][COLS];	// 2D Char Variable Array for field input
	char outputField[ROWS][COLS];	// 2D Char Variable Array for field output

	testFile(inputFile);

	boardSize(inputFile, n, m);
	setBoard(inputFile, n, m, inputField);
	formatBoard(n, m, inputField, outputField);
	output();

	system("pause");
	return 0;

}

void testFile(ifstream &inputFile){

	if (inputFile)
		return;
	else
		cout << "Error opening file. Check for proper file name and try again." << endl;
		system("pause");
		EXIT_FAILURE;
}

void boardSize(ifstream &inputFile, int &n, int &m){

	inputFile >> n;
	inputFile >> m;

}

void setBoard(ifstream &inputFile, int n, int m, char inputField[][COLS]){

	for(int row = 0; row < n; row++){
		for(int column = 0; column < m; column++){
			inputFile >> inputField[row][column];
		}
	}
}

void formatBoard(int n, int m, char inputField[][COLS], char outputField[][COLS]){

	for (int row = 0; row < n; row++){
		for(int column = 0; column < m; column++){
			if (inputField[row][column] == '*'){

				outputField[row][column] = '*';
				outputField[row][column+1];
				outputField[row+1][column];
				outputField[row+1][column+1];
			}
			

				if (row > 0 && column > 0 && outputField[row-1][column-1] != '*')
				++outputField[row-1][column-1];

				if (row > 0 && outputField[row-1][column] != '*')
				++outputField[row-1][column];

				if (row > 0 && outputField[row-1][column+1] != '*')
				++outputField[row-1][column+1];

				if (column > 0 && outputField[row][column-1] != '*')
				++outputField[row][column-1];

				if (column > 0 && outputField[row+1][column-1] != '*')
				++outputField[row+1][column-1];
		}
	}

	cout << inputField[0][0] << inputField[0][1] << inputField[0][2] << inputField[0][2] << endl;
	cout << inputField[1][0] << inputField[1][1] << inputField[1][2] << inputField[1][2] << endl;
	cout << inputField[2][0] << inputField[2][1] << inputField[2][2] << inputField[2][2] << endl;
	cout << inputField[3][0] << inputField[3][1] << inputField[3][2] << inputField[3][2] << endl;

	cout << endl << endl;

	cout << outputField[0][0] << outputField[0][1] << outputField[0][2] << outputField[0][2] << endl;
	cout << outputField[1][0] << outputField[1][1] << outputField[1][2] << outputField[1][2] << endl;
	cout << outputField[2][0] << outputField[2][1] << outputField[2][2] << outputField[2][2] << endl;
	cout << outputField[3][0] << outputField[3][1] << outputField[3][2] << outputField[3][2] << endl;
}

void output(){

	return;
}
closed account (o3hC5Di1)
Hi there,

Could you please clarify what you mean by:

However, my output at this point is just a bunch of characters, and I'm not sure how to address this.


Could you give an example of the output you expect and the output you are getting?

Thanks,
NwN
Are you sure this program compiles, it has some syntax errors:

Line 54:
EXIT_FAILURE; // should be exit ( EXIT_FAILURE ); and #include <cstdlib>

Line 80 to 82:
1
2
3
4
outputField[row][column+1];
outputField[row+1][column];
outputField[row+1][column+1];
// what are you trying to do with these lines ? 
Topic archived. No new replies allowed.