Stuck in While Loop
Nov 15, 2011 at 1:48am UTC
Hello, so for some reason, I can't get out of this while loop. The code takes a Char letter between A-I (depending on the gridSize, depends on the length the grid.) So if the grid is only 2, then you would only get the first 2 letters A, B. The max size is 9, so the last letter should be I.
The while loop makes sure the user does not go outside of the boundary of the Letter's given. When running the code, it can get into the while loop but can never get out for some reason. I've tried outputting the checkBoundX1 and checkBoundX2 to see if it is cause those numbers do not change, but they do change to the correct numbers and I just can't figure out why this is not working :(.
I apologize for the length of the code. Any and all help will be great. Thank you so much!
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
while (boundCheckX1 == 10 || boundCheckX2 == 10)
{
int boundCheckX1 = 0;
int boundCheckX2 = 0;
int check = gridSize;
cout<<"\nYou have entered a move outside of the boundaries. Please enter a new move." ;
cout<<"\n\nEnter your first point: " ;
cin>>x1>>y1;
cout<<"Enter your second point: " ;
cin>>x2>>y2;
if (gridSize == 2)
{
if (x1=='A' ||x1=='a' )
boundCheckX1 = 1;
else if (x1=='B' ||x1=='b' )
boundCheckX1 = 2;
else
boundCheckX1 = 10;
if (x2=='A' ||x2=='a' )
boundCheckX2 = 1;
else if (x2=='B' ||x2=='b' )
boundCheckX2 = 2;
else
boundCheckX2 = 10;
}
if (gridSize == 3)
{
if (x1=='A' ||x1=='a' )
boundCheckX1 = 1;
else if (x1=='B' ||x1=='b' )
boundCheckX1 = 2;
else if (x1=='C' ||x1=='c' )
boundCheckX1 = 3;
else
boundCheckX1 = 10;
if (x2=='A' ||x2=='a' )
boundCheckX2 = 1;
else if (x2=='B' ||x2=='b' )
boundCheckX2 = 2;
else if (x2=='C' ||x2=='c' )
boundCheckX2 = 3;
else
boundCheckX2 = 10;
}
if (gridSize == 4)
{
if (x1=='A' ||x1=='a' )
boundCheckX1 = 1;
else if (x1=='B' ||x1=='b' )
boundCheckX1 = 2;
else if (x1=='C' ||x1=='c' )
boundCheckX1 = 3;
else if (x1=='D' ||x1=='d' )
boundCheckX1 = 4;
else
boundCheckX1 = 10;
if (x2=='A' ||x2=='a' )
boundCheckX2 = 1;
else if (x2=='B' ||x2=='b' )
boundCheckX2 = 2;
else if (x2=='C' ||x2=='c' )
boundCheckX2 = 3;
else if (x2=='D' ||x2=='d' )
boundCheckX2 = 4;
else
boundCheckX2 = 10;
}
if (gridSize == 5)
{
if (x1=='A' ||x1=='a' )
boundCheckX1 = 1;
else if (x1=='B' ||x1=='b' )
boundCheckX1 = 2;
else if (x1=='C' ||x1=='c' )
boundCheckX1 = 3;
else if (x1=='D' ||x1=='d' )
boundCheckX1 = 4;
else if (x1=='E' ||x1=='e' )
boundCheckX1 = 5;
else
boundCheckX1 = 10;
if (x2=='A' ||x2=='a' )
boundCheckX2 = 1;
else if (x2=='B' ||x2=='b' )
boundCheckX2 = 2;
else if (x2=='C' ||x2=='c' )
boundCheckX2 = 3;
else if (x2=='D' ||x2=='d' )
boundCheckX2 = 4;
else if (x2=='E' ||x2=='e' )
boundCheckX2 = 5;
else
boundCheckX2 = 10;
}
if (gridSize == 6)
{
if (x1=='A' ||x1=='a' )
boundCheckX1 = 1;
else if (x1=='B' ||x1=='b' )
boundCheckX1 = 2;
else if (x1=='C' ||x1=='c' )
boundCheckX1 = 3;
else if (x1=='D' ||x1=='d' )
boundCheckX1 = 4;
else if (x1=='E' ||x1=='e' )
boundCheckX1 = 5;
else if (x1=='F' ||x1=='f' )
boundCheckX1 = 6;
else
boundCheckX1 = 10;
if (x2=='A' ||x2=='a' )
boundCheckX2 = 1;
else if (x2=='B' ||x2=='b' )
boundCheckX2 = 2;
else if (x2=='C' ||x2=='c' )
boundCheckX2 = 3;
else if (x2=='D' ||x2=='d' )
boundCheckX2 = 4;
else if (x2=='E' ||x2=='e' )
boundCheckX2 = 5;
else if (x2=='F' ||x2=='f' )
boundCheckX2 = 6;
else
boundCheckX2 = 10;
}
if (gridSize == 7)
{
if (x1=='A' ||x1=='a' )
boundCheckX1 = 1;
else if (x1=='B' ||x1=='b' )
boundCheckX1 = 2;
else if (x1=='C' ||x1=='c' )
boundCheckX1 = 3;
else if (x1=='D' ||x1=='d' )
boundCheckX1 = 4;
else if (x1=='E' ||x1=='e' )
boundCheckX1 = 5;
else if (x1=='F' ||x1=='f' )
boundCheckX1 = 6;
else if (x1=='G' ||x1=='g' )
boundCheckX1 = 7;
else
boundCheckX1 = 10;
if (x2=='A' ||x2=='a' )
boundCheckX2 = 1;
else if (x2=='B' ||x2=='b' )
boundCheckX2 = 2;
else if (x2=='C' ||x2=='c' )
boundCheckX2 = 3;
else if (x2=='D' ||x2=='d' )
boundCheckX2 = 4;
else if (x2=='E' ||x2=='e' )
boundCheckX2 = 5;
else if (x2=='F' ||x2=='f' )
boundCheckX2 = 6;
else if (x2=='G' ||x2=='g' )
boundCheckX2 = 7;
else
boundCheckX2 = 10;
}
if (gridSize == 8)
{
if (x1=='A' ||x1=='a' ) //1
boundCheckX1 = 1;
else if (x1=='B' ||x1=='b' ) //2
boundCheckX1 = 2;
else if (x1=='C' ||x1=='c' ) //3
boundCheckX1 = 3;
else if (x1=='D' ||x1=='d' ) //4
boundCheckX1 = 4;
else if (x1=='E' ||x1=='e' ) //5
boundCheckX1 = 5;
else if (x1=='F' ||x1=='f' ) //6
boundCheckX1 = 6;
else if (x1=='G' ||x1=='g' )
boundCheckX1 = 7;
else if (x1=='H' ||x1=='h' )
boundCheckX1 = 8;
else
boundCheckX1 = 10;
if (x2=='A' ||x2=='a' )
boundCheckX2 = 1;
else if (x2=='B' ||x2=='b' )
boundCheckX2 = 2;
else if (x2=='C' ||x2=='c' )
boundCheckX2 = 3;
else if (x2=='D' ||x2=='d' )
boundCheckX2 = 4;
else if (x2=='E' ||x2=='e' )
boundCheckX2 = 5;
else if (x2=='F' ||x2=='f' )
boundCheckX2 = 6;
else if (x2=='G' ||x2=='g' )
boundCheckX2 = 7;
else if (x2=='H' ||x2=='h' )
boundCheckX2 = 8;
else
boundCheckX2 = 10;
}
if (gridSize == 9)
{
if (x1=='A' ||x1=='a' )
boundCheckX1 = 1;
else if (x1=='B' ||x1=='b' )
boundCheckX1 = 2;
else if (x1=='C' ||x1=='c' )
boundCheckX1 = 3;
else if (x1=='D' ||x1=='d' )
boundCheckX1 = 4;
else if (x1=='E' ||x1=='e' )
boundCheckX1 = 5;
else if (x1=='F' ||x1=='f' )
boundCheckX1 = 6;
else if (x1=='G' ||x1=='g' )
boundCheckX1 = 7;
else if (x1=='H' ||x1=='h' )
boundCheckX1 = 8;
else if (x1=='I' ||x1=='i' )
boundCheckX1 = 9;
else
boundCheckX1 = 10;
if (x2=='A' ||x2=='a' )
boundCheckX2 = 1;
else if (x2=='B' ||x2=='b' )
boundCheckX2 = 2;
else if (x2=='C' ||x2=='c' )
boundCheckX2 = 3;
else if (x2=='D' ||x2=='d' )
boundCheckX2 = 4;
else if (x2=='E' ||x2=='e' )
boundCheckX2 = 5;
else if (x2=='F' ||x2=='f' )
boundCheckX2 = 6;
else if (x2=='G' ||x2=='g' )
boundCheckX2 = 7;
else if (x2=='H' ||x2=='h' )
boundCheckX2 = 8;
else if (x2=='I' ||x2=='i' )
boundCheckX2 = 9;
else
boundCheckX2 = 10;
}
}
Topic archived. No new replies allowed.