problem with ofstream?
Nov 13, 2009 at 7:37am UTC
The code I have a problem with has been shortened so that only the relevant part is in this message. I have a problem with this code in that the value for height[a][b] vanishes from 0 to 1, from certain values of a and b, as a and b increase in the loop just under the message 'check heigh BEFORE 1st sweep'. So for example, if I have height[10][11]=1, height[15][19]=1, and height[35][12]=1, first height[10][11]=0, then height[15][19]=0 and lastly height[35][12]=0. This makes no sense as none of the conditions of
(height[a][b]=height[a+1][b]) || (height[a][b]=height[a-1][b]) || (height[a][b]=height[a][b+1]) || (height[a][b]=height[a][b-1])
are satisfied, otherwise I would get one of the messages, such as 'WORKS NOW'. Thus, the value of the heights shouldnt change at all, let alone decrease one at a time.
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
for (int a=0; a<50; a++)//1st sweep
{
for (int b=0; b<50; b++)
{
if (height[a][b]>0)
{
ofstream RIGHTposition("4sink.dat" , ios::app);
RIGHTposition << "check height BEFORE 1st sweep \n" ;
for (int e=0; e<50; e++)
{ RIGHTposition << "\n" ;
for (int f=0; f<50; f++)
{RIGHTposition << height[e][f] << " " ;}
}
void close();
if (a>0 && a<49 && b>0 && b<49)//inner
{
int t=5;
int u=5;
if ( (height[a][b]=height[a+1][b]) || (height[a][b]=height[a-1][b]) || (height[a][b]=height[a][b+1]) || (height[a][b]=height[a][b-1]) )
{
t=1;
u=1;
for (int d=0; d<50; d++)
{for (int e=0; e<50; e++)
{if (island[d][e]>0)
{t=0;
u=0;
d=50;
e=50;
ofstream RIGHTposition("4sink.dat" , ios::app);
RIGHTposition <<"WORKS " << " row " << a+1 << " column " << b+1 << " Length t " << t << "NOW\n" ;
void close();}
}
}
ofstream RIGHTposition("4sink.dat" , ios::app);
RIGHTposition <<" VALUE OF t " << t << " row " << a+1 << " column " << b+1 << "YES\n" ;
void close();
if (t==1 && u==1)
{island[a][b]=1;
ofstream RIGHTposition("4sink.dat" , ios::app);
RIGHTposition <<"t " << t << " row " << a+1 << " column " << b+1 << "islandC\n" ;
void close();
}
if (t==0 && u==0)
{for (int d=49; d>-1; d--)
{
for (int e=49; e>-1; e--)
{
if (island[d][e]>0)
{
if ( (d==a+1 && e==b) || (d==a-1 && e==b) || (d==a && e==b-1) || (d==a && e==b+1) )
{
island[a][b]=island[d][e];
d=-20;
e=-20;
u=1;
ofstream RIGHTposition("4sink.dat" , ios::app);
RIGHTposition <<"t " << t << " row " << a+1 << " column " << b+1 << "islandA\n" ;
void close();
}
}
}
}
}
if (t==0 && u==0)
{int max=island[0][0];//do BEFORE d,e loop (so it doesnt keep resetting). get RID of island[d][e]>0 (is already satisfied as t=0,u=0)
for (int d=49; d>-1; d--)
{
for (int e=49; e>-1; e--)
{
if (island[d][e]>max)
{
max=island[d][e];
ofstream RIGHTposition("4sink.dat" , ios::app);
RIGHTposition <<"t " << t << " row " << a+1 << " column " << b+1 << "islandAB " << island[a][b] << "islandDE is " << island[d][e] << "\n" ;
void close();
}
}
}
island[a][b]=max+1;
}
}
ofstream RIGHTposition("4sink.dat" , ios::app);
RIGHTposition << "check height BEFORE 1st sweep STUFF\n" ;
RIGHTposition <<"\nvalues for t and u are " << t << u << "\n" ;
void close();
}//end inner
}
}
}// end of 1st sweep of islands
Nov 13, 2009 at 2:24pm UTC
These are all assignments, not comparisons:
if ( (height[a][b]=height[a+1][b]) || (height[a][b]=height[a-1][b]) || (height[a][b]=height[a][b+1]) || (height[a][b]=height[a][b-1]) )
Topic archived. No new replies allowed.