I'm a new comp sci and C++ student and I'm writing a program on my own for fun and to teach myself some basic C++ coding skills. Anyways I'm trying to write a program that will solve sudoku puzzles. I've written three functions so far. One to display the 9x9 grid, another for the user to input the initial values and another to add values to the puzzle (just the first row, I have to walk before I can run). The programs compiles fine but when it reaches the point where the computer inputs number into the puzzle board I run into a problem. Instead of entering 1 to 9 it enters ☺ ☻ ♥ ♦ ♠.
int main(int argc, char *argv[])
{
int numbers;
string more;
const int NUM_SQUARES = 81;
vector<char> board(NUM_SQUARES, EMPTY);
cout << "How many numbers do you wish to enter: ";
cin >> numbers;
do
{
for (int i = 1; i <= numbers; i++)
{
displayBoard(board);
addNumber(board);
displayBoard(board);
}
cout << "Do you want to enter any more numbers?: ";
cin >> more;
}while (more == "y");
One of the annoying features of streams is that they treat char/signed char/unsigned char types as characters rather than as integers (and there is no way to change that). guestgulkan's solution definitely works, though I don't know if it is more convenient to the rest of the program to have the vector store ASCII digits as opposed to their integer equivalents (I have not looked at the code).
I tried out jsmith's idea which fixed the output for the rowAlgorithium function but now it's displaying ascii values for the empty spaces and the numbers the user inputs.
first two row output when user enter 5 into the 5th ( first row, 6th column) vector space