While loop issue

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

While loop issue

 
0
  #1
Nov 3rd, 2008
Okay, I figured out the larger problem that I've been having with my program, now all I need is it to get out of the loop and finish the program. Well, it won't break out for some reason. Anyone see why?

  1. row = col = 4;
  2. z = 0;
  3. do { array[x][y].replace = '?';
  4. print (array, mark, col, row);
  5. ask (a, x, y, z, array, row, col, count);
  6. if (x == row-1 && y == col-1) break;
  7. }
  8. while (z == 0);

x and y are incremented in ask() and returned. So I figured if x == 3 && y == 3 , it should break from the do while loop and that would be fine. The problem is that when it returns from ask(), hits my if, and then says that the program has stopped working and needs to close.

What am I missing?
Last edited by DemonGal711; Nov 3rd, 2008 at 1:10 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

Re: While loop issue

 
0
  #2
Nov 3rd, 2008
Nevermind, got it again.
Last edited by DemonGal711; Nov 3rd, 2008 at 1:55 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: While loop issue

 
0
  #3
Nov 3rd, 2008
and then says that the program has stopped working and needs to close
Who says that? Where's the message text? Is it OS message? If so - as usually the memory is corrupted before this point.
Obviously the problem is not in this relatively simple (but questionable - for example, why if-break is not a part of do-while condition?) loop. Do you think that we all know where is your previous posts with your sources?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

Re: While loop issue

 
0
  #4
Nov 3rd, 2008
Well, I had messed with my statement a bunch of times, the original was a while where what I had in the if was stopping it.

The problem was a statement after the while was messing it up, I just forgot I had put it in there (cause all the messing with my code I had hit backspace and latched it to the end of the while end bracket. That's what was causing the error, not my while.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC