I have made a programm that determines if your integers make a magic square. There is a 2D array, which i would like to fill with numbers, but as you may know the square consists of values from 1 to (N*N) at the moment the loop checks if the integer is greater than 0 and if its not out of boundries. What I wanted to do is to check if input integer is unique, that is, if it is not used in array before. I tried to do something with another array which is filled with ones, and a do loop , but i had some problems, to execute loop as long as i get error message, that made me belive that it was just a crappy idea to try that, or it was poorly executed. Maybe anyone of you has an idea of how to execute this loop and restart it. I'd like to know it it was the right way with another array and a do loop Here is the original loop:
for (int i=0; i<N; i++)
for (int j=0; j<N; j++)
{
cin >> arr[i][j]; ///Cikls ar kura palidzibu tiek aizpildits magiskais kvadrats
if(arr[i][j] <= 0 || arr[i][j]>(N*N))
{
i=0;
j=0;
cout << error<< endl;
cin >> arr[i][j];
}
}
As for the full code it is a long and structured in a weird manner and the comments are not in english aswell, but im willing to edit it in by request if it will do any good. I'm using no libraries.
iandjto zero when it sees a value out of bounds?