I have a 2D array that I am using as my template for a Sudoku puzzle, it is a 9x9 array that I intend to have filled with numbers after getting input from the user.
I have not tried an awful lot as of yet because I am lost and haven't found and useful resources
#include <cstdlib>
#include <iostream>
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <cstdio>
#include <cstring>
#include <fstream>
using namespace std;
#define N rand() % 10
/* #define N2 rand() % 10 */
int main(){
for (int i = 0; i < 10 ; i++){
srand (time(NULL));
int c1;
int c2;
int c3;
cout << "Insert number to fill: " ;
cin >> c3;
/*c1 = N ;
c2 = N ;*/
/*cin >> c1;
cin >> c2;*/
/* cout << N << '\n'; /* << N2 << '\n'; */
int sudoku[][9] = { {0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0},};
int width = 9, height = 9;
sudoku[N][N] = c3;
cout << sudoku << '\n';
/* cout << rand()%10;*/
for (int i = 0; i < height; ++i)
{
for (int j = 0; j < width; ++j)
{
cout << sudoku[i][j] << ' ';
}
cout << endl;
}
}
return 0;
}
This is the code, it prints a 9x9 set of 0's and when I input a number it shows correctly, however when my code prompts for the next number to input, the array no longer has the previously input number. I think I have to save the array each time, maybe to a file, but I'm not entirely sure.