Why is my editSquare function not changing the value in the square?

Hi. I'm working on a project that's supposed to allow the user to play Sudoku. I believe I have most of it figured out, but when the user tries to edit the value of a square on the board, the square doesn't seem to be being changed like it should be. Can anyone help me understand why?

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/***********************************************************************
* Program:
*    project 12, Sudoku
*    Sister Unsicker, CS124
* Author:
*    Lanie Molinar
* Summary: 
*    
*
*    Estimated:  10.0 hrs   
*    Actual:     0.0 hrs
*      Please describe briefly what was the most difficult part.
************************************************************************/

#include <iostream>
#include <fstream>
using namespace std;

void getFileName(char fileName[256])
{
   cout << "Where is your board located? ";
   cin >> fileName;
}  

void readFile(char fileName[256], int board[9][9])
{
   ifstream fin(fileName);
   if (fin.fail())
   {
      cout << "Error reading file \""
         << fileName
         << "\"\n";
      return;
   }
   for (int r = 0; r < 9; r++)
      for (int c = 0; c < 9; c++)
         fin >> board[r][c];
   fin.close();
}

void displayOptions()
{
   cout << "Options:\n"
      << "   ?  Show these instructions\n"
      << "   D  Display the board\n"
      << "   E  Edit one square\n"
      << "   S  Show the possible values for a square\n"
      << "   Q  Save and Quit\n";
}

void displayBoard(int board[9][9])
{
   cout << "\n   A B C D E F G H I\n";
   for (int r = 0; r < 9; r++)
   {
      cout << r + 1
         << " ";
      for (int c = 0; c < 9; c++)
      {
         char value = (board[r][c] == 0) ? ' ' :  '0' + board[r][c];
         if (c == 8)
         {
            cout << " "
               << value
               << endl;
         }
         else if (c != 3 && c != 6)
         {
            cout << " "
               << value;
         }
         else
            cout << value;
         if(c == 2 || c == 5)
            cout << "|";
      }
      if (r == 2 || r == 5)
         cout << "   -----+-----+-----\n";
   }
}

int computeValues(int board[9][9], int r, int c)
{
   bool possible;
   return possible;
}

void editSquare(int board[9][9], int r, int c)
{
   char column = c + 65;
   computeValues(board, r, c);
      if (board[r][c] != 0)
      {
         cout << "ERROR: Square '"
         << column
         << r
         << "' is filled\n";
         return;
      }
   cout << "What is the value at '"
      << column
      << r
      << "': ";
      int value
   cin >> board[r][c];
}

void getCoordinates(int &r, int &c)
{
   cout << "What are the coordinates of the square: ";
   char column;
   cin >> column >> r;
   switch (column)
   {
      case 'a':
      case 'A':
         c = 0;
         break;
      case 'b':
      case 'B':
         c = 1;
         break;
      case 'c':
      case 'C':
         c = 2;
         break;
      case 'd':
      case 'D':
         c = 3;
         break;
      case 'e':
      case 'E':
         c = 4;
         break;
      case 'f':
      case 'F':
         c = 5;
         break;
      case 'g':
      case 'G':
         c = 6;
         break;
      case 'h':
      case 'H':
         c = 7;
         break;
      case 'i':
      case 'I':
         c = 8;
   }  
}

void displayPossible(int board[9][9], int r, int c)
{
   computeValues(board, r, c);
}

void writeBoard(int board[9][9], char fileName[256])
{
   cout << "What file would you like to write your board to: ";
   cin >> fileName;
   ofstream fout(fileName);
   for (int r = 0; r < 9; r++)
   {
      for    (int c = 0; c < 9; c++)
      {
         fout << board[r][c] << " ";
      }
      cout << endl;
   }
   if (fout.fail())
   {
      cout << "Error writing to file \""
         << fileName
         << "\"\n";
   }
   fout.close();
   cout << "Board written successfully\n";
}

void interact(int board[9][9])
{
   char fileName[256];
   int r;
   int c;
   bool possible;
   char letter;
   do
   {
      cout << "\n> ";
      cin >> letter;
      switch (letter)
      {
         case '?':
            displayOptions();     
            break;
         case 'd':
         case 'D':
            displayBoard(board);
            break;
         case 'e':
         case 'E':
            getCoordinates(r, c);
            editSquare(board, r, c);
            break;
         case 's':
         case 'S':
            getCoordinates(r, c);
            possible = computeValues(board, r, c);
      }
   }
   while (letter != 'q' && letter != 'Q');
}

/**********************************************************************
*    The main function tells a program where to start.
***********************************************************************/
int main()
{
   char fileName[256];
   int board[9][9];
   getFileName(fileName);
   readFile(fileName, board);
   displayOptions();
   displayBoard(board);
   interact(board);
   writeBoard(board, fileName);
   return 0;
}
You need to call displayBoard(...) after you modified the array / called editSquare(...), otherwise the changes are not visible for the user.

Tip: In getCoordinates(...) you can easily calculate c like so:

c = toupper(column) - 'A';

http://www.cplusplus.com/reference/cctype/toupper/?kw=toupper

And you should be prepared that the user enters wrong vallues.
Hi. I'm not supposed to call displayBoard again. I have a structure chart and an example of what the project is supposed to look like, and the board isn't shown again after the user edits a square. As for being prepared if the user enters a wrong value, I'm not supposed to do that part of the project yet. Thanks for the tip. I'll change how I compute c from column. What do I need to do to get editSquare to work, though? Thanks.
what he is saying is that edit board is probably working (it looks right) but you have to look at the board again to see that.
even if you remove the statement later, for now, call display again and LOOK at the board after using edit board to see if it worked or not. If it is working, remove the extra display if you want to.

Hi. I'll do this, but here's why I think it's not working. I'm supposed to run my code through a few tests to make sure it's working right. When I do this, I'm passing my first test but failing the rest. Here are my test results:
Starting Test 1

Open a board from a file. The contents to the file is:
7 2 3 0 0 0 1 5 9
6 0 0 3 0 2 0 0 8
8 0 0 0 1 0 0 0 2
0 7 0 6 5 4 0 2 0
0 0 4 2 0 7 3 0 0
0 5 0 9 3 1 0 4 0
5 0 0 0 7 0 0 0 3
4 0 0 1 0 3 0 0 6
9 3 2 0 0 0 7 1 4

> Where is your board located? /home/cs124/projects/sudoku.txt
> Options:
> ? Show these instructions
> D Display the board
> E Edit one square
> S Show the possible values for a square
> Q Save and Quit
>
> A B C D E F G H I
> 1 7 2 3| |1 5 9
> 2 6 |3 2| 8
> 3 8 | 1 | 2
> -----+-----+-----
> 4 7 |6 5 4| 2
> 5 4|2 7|3
> 6 5 |9 3 1| 4
> -----+-----+-----
> 7 5 | 7 | 3
> 8 4 |1 3| 6
> 9 9 3 2| |7 1 4
>
The option 'E' stands for Edit. We will prompt for a square to edit

> > E
> What are the coordinates of the square: Error! We cannot edit a filled square
A1
> ERROR: Square 'A1' is filled
>
> > E
> What are the coordinates of the square: B2
Here B2 has a 0 in it so it can be edited

> What is the value at 'B2': 9
>
> > Q
> What file would you like to write your board to: /tmp/77cd924a2323.txt
Here the edited board is saved to a file. The resulting file should be:
7 2 3 0 0 0 1 5 9
6 9 0 3 0 2 0 0 8
8 0 0 0 1 0 0 0 2
0 7 0 6 5 4 0 2 0
0 0 4 2 0 7 3 0 0
0 5 0 9 3 1 0 4 0
5 0 0 0 7 0 0 0 3
4 0 0 1 0 3 0 0 6
9 3 2 0 0 0 7 1 4
Notice the 9 in the second row and second column

> \n
Exp: Board written successfully\n
> \n
Exp: No output

Test 1 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 2

> Where is your board located? /tmp/77cd924a2323.txt
We are now opening the file we just wrote to. If the below board is not
displayed correctly, it is probably because your Save function is broken.

> Options:
> ? Show these instructions
> D Display the board
> E Edit one square
> S Show the possible values for a square
> Q Save and Quit
>
> A B C D E F G H I
> 1 7 2 3| |1 5 9
> 2 6 |3 2| 8\n
Exp: 2 6 9 |3 2| 8\n
> 3 8 9 | 1 | 2\n
Exp: 3 8 | 1 | 2\n
> -----+-----+-----
> 4 7 |6 5 4| 2
> 5 4|2 7|3
> 6 5 |9 3 1| 4
> -----+-----+-----
> 7 5 | 7 | 3
> 8 4 |1 3| 6
> 9 9 3 2| |7 1 4
>
We should be able to edit an empty square like we did before

> > E
> What are the coordinates of the square: C7
> What is the value at 'C7': 1
>
> > Q
> What file would you like to write your board to: /tmp/77cd924a2323.txt
> \n
Exp: Board written successfully\n
The saved board should be:
7 2 3 0 0 0 1 5 9
6 9 0 3 0 2 0 0 8
8 0 0 0 1 0 0 0 2
0 7 0 6 5 4 0 2 0
0 0 4 2 0 7 3 0 0
0 5 0 9 3 1 0 4 0
5 0 1 0 7 0 0 0 3
4 0 0 1 0 3 0 0 6
9 3 2 0 0 0 7 1 4
Notice the '1' in the 3rd column and 7th row. There is not a '1'
in the 7th column and 4rd row!

> \n
Exp: No output

Test 2 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 3

> Where is your board located? /tmp/77cd924a2323.txt
Again we are opening a file we saved. If this does not look the
way you expect, there is probably a bug in the save code.
> Options:
> ? Show these instructions
> D Display the board
> E Edit one square
> S Show the possible values for a square
> Q Save and Quit
>
> A B C D E F G H I
> 1 7 2 3| |1 5 9
> 2 6 |3 2| 8\n
Exp: 2 6 9 |3 2| 8\n
> 3 8 9 | 1 | 2\n
Exp: 3 8 | 1 | 2\n
> -----+-----+-----
> 4 7 |6 5 4| 2
> 5 4|2 7|3
> 6 5 |9 3 1| 4
> -----+-----+-----
> 7 5 | 7 | 3\n
Exp: 7 5 1| 7 | 3\n
> 8 4 1|1 3| 6\n
Exp: 8 4 |1 3| 6\n
> 9 9 3 2| |7 1 4
>
> > ?
> Options:
> ? Show these instructions
> D Display the board
> E Edit one square
> S Show the possible values for a square
> Q Save and Quit
>
> >
Exp: \n
Timed out!
Topic archived. No new replies allowed.