| | |
Unknown problem - Program exits during debugging
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 7
Reputation:
Solved Threads: 0
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.
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)
#include <iostream> #include <iomanip> using namespace std; void getStartState(char*, int**); void printArray(char*, int**); void updateWarehouse(int **, int **, int**); void updateKanbanBoard(int**, int**, int**); void updatePaint(int**, int**, int**); int row=0; int column=0; int participants=0; int main () { int roundNum=1; cout<<"How many colors will there be? "; cin>>row; cout<<"How many rounds? "; cin>>column; cout<<"How many assemblers/painters? "; cin>>participants; int** warehouse=new int*[row]; for (int x=0;x<row;x++) warehouse[x]=new int[column]; int** kanbanBoard=new int*[row]; for (int x=0;x<row;x++) kanbanBoard[x]=new int[column]; int** paint=new int*[row]; for (int x=0;x<row;x++) paint[x]=new int[column]; int** assembly=new int*[row]; for (int x=0;x<row;x++) assembly[x]=new int[column]; int** temp=new int*[row]; for (int x=0;x<row;x++) temp[x]=new int[column]; cout<<"Enter start state for game (make sure you put the\n"; cout<<"colors into the program in the same order everytime.)\n"; getStartState("Warehouse",warehouse); getStartState("Kanban Board",kanbanBoard); getStartState("Paint",paint); //getStartState two (special case for paint) cout<<"Paint round 2"<<endl; for (int x=0;x<row;x++) cin>>paint[x][1]; getStartState("Assembly round 2",assembly); while(roundNum<column) { cout<<"Enter Assembly numbers for round "<<roundNum+2<<endl; for (int x=0;x<row;x++) { cin>>assembly[x][roundNum]; } roundNum++; }; updateWarehouse(warehouse, paint, assembly); updateKanbanBoard(kanbanBoard, assembly, temp); updatePaint(kanbanBoard, paint, temp); printArray("Warehouse",warehouse); printArray("Kanban Board",kanbanBoard); printArray("Paint",paint); printArray("Assembly",assembly); return 0; } void getStartState(char* a, int** b) { cout<<a<<endl; for (int x=0;x<row;x++) cin>>b[x][0]; }; void printArray(char* a, int** b) { cout<<a<<endl; for (int x=0;x<row;x++) { for (int i=0;i<column;i++) cout<<b[x][i]<<","; cout<<endl; } cout<<endl; }; void updateWarehouse(int** warehouse, int** paint, int** assembly) { for (int x=0;x<row;x++) { for (int i=1;i<column;i++) { warehouse[x][i]=(warehouse[x][i-1]+paint[x][i-1])-assembly[x][i-1]; } } }; void updateKanbanBoard(int** kanban, int** assembly, int**temp) { for (int r=0;r<row;r++) { temp[r][0]=kanban[r][0]; } for (int c=1;c<column;c++) { for(int r=0;r<row;r++) { kanban[r][c]=kanban[r][c-1]+assembly[r][c-1]; temp[r][c]=kanban[r][c]; } int cardsRemoved=0; for (int x=0;x<participants;x++) { int greatestNum=-1; for (int r=1;r<row;r++) { if(greatestNum!=-1) { if(kanban[greatestNum][c]<kanban[r][c]) greatestNum=r; } else { if(kanban[r][c]>kanban[r-1][c]) greatestNum=r; if(kanban[r-1][c]>kanban[r][c]) greatestNum=r-1; } } if(greatestNum!=-1) { kanban[greatestNum]=kanban[greatestNum]-1; cardsRemoved++; } } while (cardsRemoved<participants) { int r=0; kanban[r][c]=kanban[r][c]-1; r++; cardsRemoved++; } } }; void updatePaint(int** kanban, int** paint, int** temp) { for(int c=2;c<column;c++) { for(int r=0;r<row;r++) { paint[r][c]=temp[r][c-1]-kanban[r][c-1]; } } };
Last edited by j_p36; Nov 19th, 2008 at 1:14 pm.
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.
See if that helps any
-- Semi-colons.
C++ Syntax (Toggle Plain Text)
while(roundNum<column) { cout<<"Enter Assembly numbers for round "<<roundNum+2<<endl; for (int x=0;x<row;x++) { cin>>assembly[x][roundNum]; } roundNum++; }; // you dont need me <--------------------------------- look
C++ Syntax (Toggle Plain Text)
void getStartState(char* a, int** b) { ... }; < ------------------------------------------- me either void printArray(char* a, int** b) { ... }; < -------------------------------------------------- me either void updateWarehouse(int** warehouse, int** paint, int** assembly) { ... }; < ------------------------------------------------------ me either void updateKanbanBoard(int** kanban, int** assembly, int**temp) { ... }; < ----------------------------------------- me either void updatePaint(int** kanban, int** paint, int** temp) { ... }; <------------------------------------- me either
See if that helps any
Last edited by chococrack; Nov 19th, 2008 at 1:21 pm.
I would love to change the world, but they won't give me the source code
•
•
Join Date: Nov 2008
Posts: 7
Reputation:
Solved Threads: 0
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?
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
alrighty, so with those specific numbers the output looks like this:
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
C++ Syntax (Toggle Plain Text)
How many colors will there be? 3 How many rounds? 5 How many assemblers/painters? 3 Enter start state for game (make sure you put the colors into the program in the same order everytime.) Warehouse 3 3 3 Kanban Board 3 3 3 Paint 1 1 1 Paint round 2 1 1 1 Assembly round 2 1 2 0 Enter Assembly numbers for round 3 0 1 2 Enter Assembly numbers for round 4 1 0 2 Enter Assembly numbers for round 5 0 2 1 Enter Assembly numbers for round 6 1 1 1 Warehouse 3,3,4,3,3, 3,2,2,2,0, 3,4,3,1,0, Kanban Board 134525044,134525076,25,2,2, 2,3,3,0,2, 0,0,25,3,3, Paint 1,1,-134525072,-23,1, 1,1,2,1,25, 1,1,3,-20,2, Assembly 1,0,1,0,1, 2,1,0,2,1, 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.
I would love to change the world, but they won't give me the source code
•
•
Join Date: Nov 2008
Posts: 7
Reputation:
Solved Threads: 0
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)
How many colors will there be? 3 How many rounds? 5 How many assemblers/painters? 3 Enter start state for game (make sure you put the colors into the program in the same order everytime.) Warehouse 3 3 3 Kanban Board 3 3 3 Paint 1 1 1 Paint round 2 1 1 1 Assembly round 2 1 2 0 Enter Assembly numbers for round 3 0 1 2 Enter Assembly numbers for round 4 1 0 2 Enter Assembly numbers for round 5 0 2 1 Enter Assembly numbers for round 6 1 1 1 Warehouse 3,3,4,-842150448,-1684300899, 3,2,2,-842150449,-1684300902, 3,4,3,-842150450,-1684300902, Kanban Board 1,143,-33686019,2,2, 1,144,-33686019,-33686019,-33686017, 0,20,1,145,-33686019, Paint 1,1,-139,33686021,1, 1,1,-139,33686023,0, 1,1,-17,4,-140, Assembly 1,0,1,0,1, 2,1,0,2,1, 0,2,2,1,1, Press any key to continue . . .
A rather strange loop, see what happens:
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
Regrettably, I have no time to check up more codes at the moment. Correct (trivial correction) this fragment and continue...
C++ Syntax (Toggle Plain Text)
while (cardsRemoved<participants) { int r = 0; // r created on every loop, initialized 0 kanban[r][c]=kanban[r][c]-1; // always [0][c] = [0][c] r++; // incremented, but r shall die soon cardsRemoved++; // automatic r ended }
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...
•
•
Join Date: Nov 2008
Posts: 7
Reputation:
Solved Threads: 0
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)
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)
int z=0; while (cardsRemoved<participants) { kanban[z][c]=kanban[z][c]-1; z++; cardsRemoved++; }
Last edited by j_p36; Nov 19th, 2008 at 6:55 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: C++ homework...Please help!!
- Next Thread: Alt-F4
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






