my switch statement is not working properly. it works fine till case 'C', after that nothing is happening.
Any ideas?
void processData(List<Movies>& myList, Stack<Movies>& myStack, Queue<Movies>& myQ){
Movies movieObj;
int numInStack = 0,
numInQ = 0,
num2process = 0;
fstream inFile("newReturns.txt");
if(!inFile){
cout << "Unable to open Returns.txt." << endl;
exit(99);
}
fstream outFile("MovieReport.txt", ios::app|ios::in);
if(!outFile){
cout << "Unable to open MovieReport.txt." << endl;
exit(99);
}
outFile << endl;
cout << "---TEST--- before reading the newReturns.txt" << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST--- before reading the newReturns.txt\n" << endl;
inFile >> movieObj.x;
inFile >> movieObj.MPAC;
while(!inFile.eof()){
switch(movieObj.x){
case 'C':
if(myList.getItem(movieObj)){
cout << myList.getItem(movieObj) << " true or false? \n" << endl;
movieObj.checkedIn--;
movieObj.checkedOut++;
myList.updateData(movieObj);
cout << movieObj.MPAC << " - has been checked out. " << endl;
outFile << movieObj.MPAC << " - has been checked out. " << endl;
cout << "---TEST--- after reading C " << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST--- after reading C\n" << endl;
}else{
outFile << movieObj.MPAC << " - was not found." << endl;
}break;
case 'Q':
cout << "QUEUE IS: " << numInQ << "\n" << endl;
myQ.enQueue(movieObj);
outFile << movieObj.MPAC << " - was added to the Queue." << endl;
numInQ++;
cout << "---TEST--- after reading Q" << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST--- before reading Q\n" << endl;
break;
case 'R':
myStack.push(movieObj);
outFile << movieObj.MPAC << " - was returned and was added to the processing list. " << endl;
numInStack++;
cout << "---TEST--- after reading R" << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST--- before reading R\n" << endl;
break;
case 'P':
Movies movieInfo;
cout << "---TEST--- as soon as reading P" << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST--- as soon as reading P\n" << endl;
if(movieObj.MPAC > numInQ){
for(int i = 0; i < numInQ; i++){
myQ.peek(movieInfo);
if(myList.getItem(movieInfo)){
movieInfo.checkedIn++;
movieInfo.checkedOut--;
myList.updateData(movieInfo);
cout << movieInfo.MPAC << " HAS BEEN PROCESSED. " << endl;
num2process--;
}
}numInQ = 0;
cout << "---TEST---if the mpac > numInQ" << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST---\n" << endl;
for(int i = 0; i < num2process; i++){
myStack.peek(movieInfo);
if(myList.getItem(movieInfo)){
movieInfo.checkedIn++;
movieInfo.checkedOut--;
myList.updateData(movieInfo);
cout << movieInfo.MPAC << " HAS BEEN PROCESSED. " << endl;
numInStack--;
}
cout << "---TEST--- now doing the R" << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST---\n" << endl;
}
}else{
if(num2process < numInQ){
for(int i=0; i < num2process; i++){
myQ.peek(movieInfo);
if(myList.getItem(movieInfo)){
movieInfo.checkedIn++;
movieInfo.checkedOut--;
cout << movieInfo.MPAC << " HAS BEEN PROCESSED. " << endl;
}numInQ--;
}
cout << "---TEST--- if the num2process < numInQ" << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST---\n" << endl;
}else{
for(int i=0; i < numInQ; i++){
myQ.peek(movieInfo);
if(myList.getItem(movieInfo)){
movieInfo.checkedIn++;
movieInfo.checkedOut--;
cout << movieInfo.MPAC << " HAS BEEN PROCESSED. " << endl;
}num2process--;
}
cout << "---TEST--- if num2process = numInQt" << endl;
cout << numInStack << " --- " << numInQ << " --- " << num2process << endl;
cout << "---TEST---\n" << endl;
numInQ = 0;
}
}
}break;
inFile >> movieObj.x;
inFile >> movieObj.MPAC;
}
cout << "Processing the stack is done.\n" << endl;
inFile.close();
outFile.close();