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.
#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];
}
}
};