little problem
Sep 10, 2013 at 10:03pm UTC
Hello,
I have a little problem with this code. It does not work properly. If I type 0's as my input for each element of an array, the output is quite weird. I expect that each iteration should validate these values: 1,1,1,2,2,2,3,3,3,4,4,4; when the value of the counter z is more than 2 i want to see only 1,2,3,4 for each element. This works fine for the first 3 elements but later on some values disappear.
Could it be that a compiler cannot digest this many "for loops"?
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
#include <iostream>
using namespace std;
int main()
{int m,x,y,z,i,l[4][4];
z=0;
for (x=0; x<=3; x++){for (y=0;y<=3;y++){cin >> l[x][y];};};
for (x=0; x<=3; x++){for (y=0;y<=3;y++){cout << l[x][y] << ' ' ;}cout<<"\n" ;};
for (x=0; x<=3; x++){for (y=0;y<=3;y++){if (l[x][y]==0){
for (l[x][y]=1;l[x][y]<=4;l[x][y]++){
for (i=1;i<=3;i++){
if (l[x+i][y]!=l[x][y]){if (l[x-i][y]!=l[x][y]){cout << "" ;
switch (y){
case 0:if (y+i<=3){cout<< "" ;
if (l[x][y+i]!=l[x][y]){cout<<"" ;
z++; if (z>2){cout << l[x][y] <<' ' <<"|" ;};};};break ;
case 3:
if (true ){cout<<"" ;
if (l[x][y-i]!=l[x][y]){cout<<"" ;
z++; if (z>2){cout << l[x][y] <<' ' <<"|" ;};};};break ;
default :if (y+i<=3){cout<< "" ;
if (l[x][y+i]!=l[x][y]){cout<<"" ;
for (m=1;m<=3;m++){cout<<"" ;
if (y-i>=0){cout<<"" ;
if (l[x][y-i]!=l[x][y]){cout<<"" ;
z++; if (z>2){cout << l[x][y] <<' ' <<"|" ;};};};};};};break ;
};
};};}; z=0;};cout<<"." ;l[x][y]=0;};};cout<<"\n" ;}; cout <<"\n" ;
cout << "\n" ;
cout << l[0][1] << l[0][1] << l[0][2] << l[0][3];
cout << "\n" ;
cin>>z;
return 0;
}
Sep 10, 2013 at 10:12pm UTC
There's no such thing as "a compiler [that] cannot digest this many [a lot of] 'for loops'"; you have a logical error.
Explain what you're trying to do; it's unclear.
Sep 10, 2013 at 10:17pm UTC
code which checks for unique values in a line and column.
Topic archived. No new replies allowed.