943,809 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 981
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 19th, 2008
0

Unknown problem - Program exits during debugging

Expand Post »
Ok, so I've been working on this code for a day now and i thought I had all the kinks worked out, but my program isn't working right. I'm writing this code to simulate a game (basically a simulation of a simulation) used to illustrate some topics we are trying to teach at work. I'll try to explain a few things then get to the code. As of now the game is running with 3 colors of cards (which i use rows in a dynamic 2d array to keep up with, ie row 0 of every array is the number of cards that are red), and the cards are moving from an assembly department to a kanban board to a paint department. the cards are used as a linkage between the assembly department and the paint department.

With this said, when I run the program without debugging, I think all the arrays are working properly except kanbanBoard, which is used to calculate some of the other arrays, and I think the errors in that array are causing the very wrong numbers in the other arrays. I have stepped through the code on paper and it seems like the logic is coded correctly but I'm not sure.
The updateKanbanBoard function is supposed to remove a card from the largest stack and repeat that process until it has done that step the same number of times are there are in the paint/assembly department. then if cardsRemoved!= the number of participants then it should remove 1 from each stack starting at the left until cardsRemoved==the number of participants.

Now that all of that is explained, when I run the code I get trash data from kanbanBoard propagating through the others. When I debug the code it runs until it hits line 122 then it gives me this message

'Kanban Simulation.exe': Loaded 'C:\Documents and Settings\jpettitt\My Documents\Visual Studio 2008\Projects\Kanban Simulation\Debug\Kanban Simulation.exe', Symbols loaded.
'Kanban Simulation.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'Kanban Simulation.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'Kanban Simulation.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcp90d.dll'
'Kanban Simulation.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcr90d.dll'
The program '[3704] Kanban Simulation.exe: Native' has exited with code 0 (0x0).

Which I'm pretty sure means the program exited. Why would it do this in the middle of a function when I hadn't told it to exit? Why does the program run to completion when I don't debug but with trash data?

The numbers I am inputting to test the program are: (just press the number then press enter and repeat.)
3,5,3 3,3,3 3,3,3 1,1,1 1,1,1 1,2,0 0,1,2 1,0,2 0,2,1 1,1,1

here is the code

I'm fairly sure that the problem is in updateKanbanBoard, but I posted the whole code because the problem might not be there, and it wasn't to terribly long.

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. void getStartState(char*, int**);
  6. void printArray(char*, int**);
  7. void updateWarehouse(int **, int **, int**);
  8. void updateKanbanBoard(int**, int**, int**);
  9. void updatePaint(int**, int**, int**);
  10. int row=0;
  11. int column=0;
  12. int participants=0;
  13.  
  14. int main ()
  15. {
  16. int roundNum=1;
  17. cout<<"How many colors will there be? ";
  18. cin>>row;
  19. cout<<"How many rounds? ";
  20. cin>>column;
  21. cout<<"How many assemblers/painters? ";
  22. cin>>participants;
  23. int** warehouse=new int*[row];
  24. for (int x=0;x<row;x++)
  25. warehouse[x]=new int[column];
  26.  
  27. int** kanbanBoard=new int*[row];
  28. for (int x=0;x<row;x++)
  29. kanbanBoard[x]=new int[column];
  30.  
  31. int** paint=new int*[row];
  32. for (int x=0;x<row;x++)
  33. paint[x]=new int[column];
  34.  
  35. int** assembly=new int*[row];
  36. for (int x=0;x<row;x++)
  37. assembly[x]=new int[column];
  38.  
  39. int** temp=new int*[row];
  40. for (int x=0;x<row;x++)
  41. temp[x]=new int[column];
  42.  
  43. cout<<"Enter start state for game (make sure you put the\n";
  44. cout<<"colors into the program in the same order everytime.)\n";
  45.  
  46. getStartState("Warehouse",warehouse);
  47. getStartState("Kanban Board",kanbanBoard);
  48. getStartState("Paint",paint);
  49. //getStartState two (special case for paint)
  50. cout<<"Paint round 2"<<endl;
  51. for (int x=0;x<row;x++)
  52. cin>>paint[x][1];
  53. getStartState("Assembly round 2",assembly);
  54.  
  55. while(roundNum<column)
  56. {
  57. cout<<"Enter Assembly numbers for round "<<roundNum+2<<endl;
  58. for (int x=0;x<row;x++)
  59. {
  60. cin>>assembly[x][roundNum];
  61. }
  62. roundNum++;
  63. };
  64.  
  65. updateWarehouse(warehouse, paint, assembly);
  66. updateKanbanBoard(kanbanBoard, assembly, temp);
  67. updatePaint(kanbanBoard, paint, temp);
  68.  
  69. printArray("Warehouse",warehouse);
  70. printArray("Kanban Board",kanbanBoard);
  71. printArray("Paint",paint);
  72. printArray("Assembly",assembly);
  73.  
  74. return 0;
  75. }
  76.  
  77. void getStartState(char* a, int** b)
  78. {
  79. cout<<a<<endl;
  80. for (int x=0;x<row;x++)
  81. cin>>b[x][0];
  82. };
  83. void printArray(char* a, int** b)
  84. {
  85. cout<<a<<endl;
  86. for (int x=0;x<row;x++)
  87. {
  88. for (int i=0;i<column;i++)
  89. cout<<b[x][i]<<",";
  90. cout<<endl;
  91. }
  92. cout<<endl;
  93. };
  94.  
  95. void updateWarehouse(int** warehouse, int** paint, int** assembly)
  96. {
  97. for (int x=0;x<row;x++)
  98. {
  99. for (int i=1;i<column;i++)
  100. {
  101. warehouse[x][i]=(warehouse[x][i-1]+paint[x][i-1])-assembly[x][i-1];
  102. }
  103. }
  104. };
  105.  
  106. void updateKanbanBoard(int** kanban, int** assembly, int**temp)
  107. {
  108. for (int r=0;r<row;r++)
  109. {
  110. temp[r][0]=kanban[r][0];
  111. }
  112. for (int c=1;c<column;c++)
  113. {
  114. for(int r=0;r<row;r++)
  115. {
  116. kanban[r][c]=kanban[r][c-1]+assembly[r][c-1];
  117. temp[r][c]=kanban[r][c];
  118. }
  119. int cardsRemoved=0;
  120. for (int x=0;x<participants;x++)
  121. {
  122. int greatestNum=-1;
  123. for (int r=1;r<row;r++)
  124. {
  125. if(greatestNum!=-1)
  126. {
  127. if(kanban[greatestNum][c]<kanban[r][c])
  128. greatestNum=r;
  129. }
  130. else
  131. {
  132. if(kanban[r][c]>kanban[r-1][c])
  133. greatestNum=r;
  134. if(kanban[r-1][c]>kanban[r][c])
  135. greatestNum=r-1;
  136. }
  137. }
  138. if(greatestNum!=-1)
  139. {
  140. kanban[greatestNum]=kanban[greatestNum]-1;
  141. cardsRemoved++;
  142. }
  143. }
  144. while (cardsRemoved<participants)
  145. {
  146. int r=0;
  147. kanban[r][c]=kanban[r][c]-1;
  148. r++;
  149. cardsRemoved++;
  150. }
  151. }
  152. };
  153.  
  154. void updatePaint(int** kanban, int** paint, int** temp)
  155. {
  156. for(int c=2;c<column;c++)
  157. {
  158. for(int r=0;r<row;r++)
  159. {
  160. paint[r][c]=temp[r][c-1]-kanban[r][c-1];
  161. }
  162. }
  163. };
Last edited by j_p36; Nov 19th, 2008 at 1:14 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j_p36 is offline Offline
15 posts
since Nov 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

Plu-cha... before I go diving into analyzing 2d arrays and such, I want to see if maybe the following easy fixes help anything:

-- Semi-colons.
C++ Syntax (Toggle Plain Text)
  1. while(roundNum<column)
  2. {
  3. cout<<"Enter Assembly numbers for round "<<roundNum+2<<endl;
  4. for (int x=0;x<row;x++)
  5. {
  6. cin>>assembly[x][roundNum];
  7. }
  8. roundNum++;
  9. }; // you dont need me <--------------------------------- look

C++ Syntax (Toggle Plain Text)
  1. void getStartState(char* a, int** b)
  2. {
  3. ...
  4.  
  5. }; < ------------------------------------------- me either
  6. void printArray(char* a, int** b)
  7. {
  8.  
  9. ...
  10.  
  11. }; < -------------------------------------------------- me either
  12.  
  13. void updateWarehouse(int** warehouse, int** paint, int** assembly)
  14. {
  15.  
  16. ...
  17.  
  18. }; < ------------------------------------------------------ me either
  19.  
  20. void updateKanbanBoard(int** kanban, int** assembly, int**temp)
  21. {
  22.  
  23. ...
  24.  
  25. }; < ----------------------------------------- me either
  26.  
  27. void updatePaint(int** kanban, int** paint, int** temp)
  28. {
  29.  
  30. ...
  31.  
  32. }; <------------------------------------- me either


See if that helps any
Last edited by chococrack; Nov 19th, 2008 at 1:21 pm.
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

I removed the semi-colons and I ran without debugging and with debugging, both gave same results as before.

(I would have sworn that you needed those though, guess I just remembered something wrong from intro years ago.)
Last edited by j_p36; Nov 19th, 2008 at 1:29 pm. Reason: grammer
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j_p36 is offline Offline
15 posts
since Nov 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

I was prepared for the possibility that they would solve nothing. Alright I'm going to look at your code a little bit more and see if I can find anything else.
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

Awesome, I really appreciate the help, I've been banging my head against my desk all morning trying to fix this...

Also, i know that I never de-allocated the memory from all those pointers, but I wanted to get the program giving correct numbers before i worried about possible memory leaks, is this an ok strategy or could this possibly be the problem?
Last edited by j_p36; Nov 19th, 2008 at 1:36 pm. Reason: added info
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j_p36 is offline Offline
15 posts
since Nov 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

Also, since I didn't have line numbers on the posted code the line in updateKanbanBoard where greatestNum is declared and initiated is the line where the debugger exits the program I believe. It is line 122 though.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j_p36 is offline Offline
15 posts
since Nov 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

alrighty, so with those specific numbers the output looks like this:

C++ Syntax (Toggle Plain Text)
  1.  
  2. How many colors will there be? 3
  3. How many rounds? 5
  4. How many assemblers/painters? 3
  5. Enter start state for game (make sure you put the
  6. colors into the program in the same order everytime.)
  7. Warehouse
  8. 3
  9. 3
  10. 3
  11. Kanban Board
  12. 3
  13. 3
  14. 3
  15. Paint
  16. 1
  17. 1
  18. 1
  19. Paint round 2
  20. 1
  21. 1
  22. 1
  23. Assembly round 2
  24. 1
  25. 2
  26. 0
  27. Enter Assembly numbers for round 3
  28. 0
  29. 1
  30. 2
  31. Enter Assembly numbers for round 4
  32. 1
  33. 0
  34. 2
  35. Enter Assembly numbers for round 5
  36. 0
  37. 2
  38. 1
  39. Enter Assembly numbers for round 6
  40. 1
  41. 1
  42. 1
  43. Warehouse
  44. 3,3,4,3,3,
  45. 3,2,2,2,0,
  46. 3,4,3,1,0,
  47.  
  48. Kanban Board
  49. 134525044,134525076,25,2,2,
  50. 2,3,3,0,2,
  51. 0,0,25,3,3,
  52.  
  53. Paint
  54. 1,1,-134525072,-23,1,
  55. 1,1,2,1,25,
  56. 1,1,3,-20,2,
  57.  
  58. Assembly
  59. 1,0,1,0,1,
  60. 2,1,0,2,1,
  61. 0,2,2,1,1,

So, as you said before KanbanBoard needs some attention. More than likely (obviously even) the Kanban Board is either not getting the correct value or is referencing the wrong array item.

Digging in now.. bbl
Last edited by chococrack; Nov 19th, 2008 at 5:15 pm.
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

What comes up when I run mine looks a little different. I guess its just because of the way pointers work with pointing to memory and such.

C++ Syntax (Toggle Plain Text)
  1. How many colors will there be? 3
  2. How many rounds? 5
  3. How many assemblers/painters? 3
  4. Enter start state for game (make sure you put the
  5. colors into the program in the same order everytime.)
  6. Warehouse
  7. 3
  8. 3
  9. 3
  10. Kanban Board
  11. 3
  12. 3
  13. 3
  14. Paint
  15. 1
  16. 1
  17. 1
  18. Paint round 2
  19. 1
  20. 1
  21. 1
  22. Assembly round 2
  23. 1
  24. 2
  25. 0
  26. Enter Assembly numbers for round 3
  27. 0
  28. 1
  29. 2
  30. Enter Assembly numbers for round 4
  31. 1
  32. 0
  33. 2
  34. Enter Assembly numbers for round 5
  35. 0
  36. 2
  37. 1
  38. Enter Assembly numbers for round 6
  39. 1
  40. 1
  41. 1
  42. Warehouse
  43. 3,3,4,-842150448,-1684300899,
  44. 3,2,2,-842150449,-1684300902,
  45. 3,4,3,-842150450,-1684300902,
  46.  
  47. Kanban Board
  48. 1,143,-33686019,2,2,
  49. 1,144,-33686019,-33686019,-33686017,
  50. 0,20,1,145,-33686019,
  51.  
  52. Paint
  53. 1,1,-139,33686021,1,
  54. 1,1,-139,33686023,0,
  55. 1,1,-17,4,-140,
  56.  
  57. Assembly
  58. 1,0,1,0,1,
  59. 2,1,0,2,1,
  60. 0,2,2,1,1,
  61.  
  62. Press any key to continue . . .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j_p36 is offline Offline
15 posts
since Nov 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

A rather strange loop, see what happens:
C++ Syntax (Toggle Plain Text)
  1. while (cardsRemoved<participants)
  2. {
  3. int r = 0; // r created on every loop, initialized 0
  4. kanban[r][c]=kanban[r][c]-1; // always [0][c] = [0][c]
  5. r++; // incremented, but r shall die soon
  6. cardsRemoved++; // automatic r ended
  7. }
Probably you forgot that the loop body is a block. The r variable is declared in this block. It's created anew with value 0 on every loop. Result: kanban[0][c] decremented while cardsRemoved<participants . Obviously it's not a desired effect.

Regrettably, I have no time to check up more codes at the moment. Correct (trivial correction) this fragment and continue...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Nov 19th, 2008
0

Re: Unknown problem - Program exits during debugging

ArkM thanks for pointing that out, I hadn't paid enough attention to that particular loop to notice that it wasn't really doing what I intended. After the change I still get the garbage data and the debugger exiting, but that is one problem that would have kept the program from working correctly so I appreciate it.

new code (can be pasted over the previous while loop, and I used z since I hadn't used it previously in the program)

C++ Syntax (Toggle Plain Text)
  1. int z=0;
  2. while (cardsRemoved<participants)
  3. {
  4. kanban[z][c]=kanban[z][c]-1;
  5. z++;
  6. cardsRemoved++;
  7. }
Last edited by j_p36; Nov 19th, 2008 at 6:55 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j_p36 is offline Offline
15 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ homework...Please help!!
Next Thread in C++ Forum Timeline: Alt-F4





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC