### Minesweeper

Try to write a program to give Minesweeper fields hints.

INPUT
The input will consist of an arbitrary number of fields. The first line of each field contains two integers,n and m(1<=n,m<=100), which stands for the number of lines and columns of the field respectively. The next n lines contain exactly m characters and represent the field. Each safe square is represented by an "." character and each mine square are represented by a "*" character. The first field line where n=m=0 represents the end of input and should not be processed.

OUTPUT
For each field, print "Field #x:"(x = the number of the field starting from 1) in a line alone.
The next n lines should contain the field with the "." characters replaced by the number of adjacent mines to that square. There should be an empty line between field outputs.

PROBLEM
Keep having errors and very buggy :(

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980`` ``````#include using namespace std; int m=0; int cField,rField; int main(){ cin>>cField>>rField; while(cField*rField!=0){ char char(m+65)[cField][rField]; for(int i=0;i>char(m+65)[i][j]; } } int result_m[cField][rField]; for(int i=0;i>cField>>rField; }//for j cout<

Thanks a lot!
Hello kryptomega,

Line 2. Something you should avoid using. In the future it WILL cause you bigger problems. You should learn what is in the "std" name space and how to qualify what is needed like; "std::cout", "std::cin" and "std::endl" for a start.

Lines 3 and 4 are OK, but you should try to avoid global variables. A variable that starts with "constexpr" or const" is OK. Also do not count on a global variable being initialized. You should ALWAYS initialize your variables to be safe.

What is you point with line 9? As is you are trying to give something a type twice, or did you mean to use the second "char" as a type cast? I am not sure if "(m + 65)" will work here. It might be better to define "m" as a "char" and use "(m + 'A') for a better understanding of what you mean to do. Then there is the part
"`[cField][rField]`". This is not allowed in C++. What is between the "[]"s needs to be a constant value not a variable. Maybe it works in older C compilers, but not today. If you need to use these variables you either need to create a dynamic array or use them to limit the use of a larger array, as in how much of the array is used.

Last point the variable names "cField" and "rField" would lead one to believe "r" stands for row and "c" stands for column. If this is the case you are using them backwards when defining the array because in a 2D array the row comes first then the column. Also instead of using "(m + 65)" for the array name it would be easier to just call it "board". And if you have an idea of changing the value of "m" to create a second or third array what is the point of the additional arrays?

Until I fix the errors I can not test the program yet.

Hope that helps,

Andy
Hello Andy,

OK, I'll try. Thanks a lot!

kryptomega