int readTimeSlice(PCB & current, int maxSlice){ int timeSlice; cout << "How long was this process in the CPU: "; cin >> timeSlice; cout << endl; while(!cin || timeSlice < 0 || timeSlice > maxSlice) { cout << "Time must be between 0 and " << maxSlice << "ms" << endl << endl; cout << "How long was this process in the CPU: "; cin.clear(); cin.ignore(100,'\n'); cin >> timeSlice; cout << endl; } current.updateProcessTime(timeSlice); //current.increaseCpuCount(); cout <<"Total CPU Process time has been updated" << endl << endl; cout <<"Current CPU Time is " << current.getTotalProcessTime() << "ms for process " << current.getPID() << endl; cout << endl; return timeSlice; }
void MainProcess::Destroy(str PID) { //Check for process existence std::vector<str>::iterator findIt = std::find(nameList.begin(), nameList.end(), PID); if (findIt == nameList.end()){ std::cout << "error "; ss << "error "; return; } //Remove from name list nameList.erase(findIt); PCB* temp; //Search the ready list for the PCB with the specified PID for (int i = 1; i < 3; i++){ //for (PCB* p : readyList[i]) for (std::list<PCB*>::iterator it = readyList[i].begin(); it != readyList[i].end(); it++) { if ((*it)->getPID() == PID){ temp = *it; readyList[i].erase(it); KillTree(temp); Scheduler(); return; } } } temp = TreeSearch(PID, &initProcess); if (temp->getPID() != PID){ std::cout << "error "; ss << "error "; return; } KillTree(temp); //Scheduler(); return; }
PCB* MainProcess::TreeSearch(str pID, PCB* p){ if (p->getPID() != pID){ PCB* temp; if (!p->children.empty()){ for (PCB* q : p->children){ temp = TreeSearch(pID, q); if (temp->getPID() == pID) return temp; } } } return p; }
int main(int argc, const char * argv[]) { int printerNum; int cdrwNum; int diskNum; int timeSlice; int terminatedProcessCount = 0; int terminatedProcessTotalTime = 0; float totalAveTerminatedCpuTime = 0; //int cylinderNum; int systemPID = 0; int totalMemSize = 0; int processSize = 0; int roundedProcessSize = 0; int maxProcessSize; int pageSize = 0; int freeMem = 0; int usedMem = 0; pair<bool, int> activeRecord; string userInput; vector<int> cylinderNum; vector<deque<PCB> > printers; vector<FscanDiskQueue> disks; vector<deque<PCB> > cdrws; vector<pair<bool, int>> frameList; deque<PCB> printerQueue; FscanDiskQueue diskQueue; deque<PCB> cdrwQueue; deque<PCB> readyQueue; deque<PCB> jobPool; printWelcome(); cout << "*************SYS GEN***************" << endl; //SYS GEN***************************************** //************TotalMemSize**************** cout << "What is the total Memory Size: "; cin >> totalMemSize; cout << endl; while((!cin || totalMemSize < 1|| (totalMemSize == 0)) || !memContraintCheck(totalMemSize) ) { cout << "Invalid Input!" << endl; cout << "Total Memory Size should be divisible by a power of 2" << endl << endl; cout << "What is the total Memory Size: "; cin.clear(); cin.ignore(100,'\n'); cin >> totalMemSize; cout << endl; } cout << " The Total Memory Size is " << totalMemSize << " Words" << endl; cout << endl; //************MaxProcessSize**************** cout << "What is the Max Process Size: "; cin >> maxProcessSize; cout << endl; while(!cin || maxProcessSize < 1 || maxProcessSize > totalMemSize) { cout << "Invalid Input!" << endl; cout << "Max Process size must be less than Total Memory Size." << endl; cout << "What is the Max Process Size: "; cin.clear(); cin.ignore(100,'\n'); cin >> maxProcessSize; cout << endl; } cout << " The Max Process Size is " << maxProcessSize << " Words" << endl; cout << endl; //************PageSize**************** cout << "What is the Page Size(Powers of 2 only): "; cin >> pageSize; cout << endl; while(!cin || pageSize < 1 || totalMemSize % pageSize != 0 || (pageSize == 0) || (pageSize & (pageSize - 1)) ) { cout << "Invalid Input!" << endl; cout << "Page Size must be a power of 2 and divide Memory evenly" << endl << endl; cout << "What is the Page Size: "; cin.clear(); cin.ignore(100,'\n'); cin >> pageSize; cout << endl; } cout << " The Page Size is " << pageSize << " Words" << endl; cout << endl; //cout << "Total Memory size must be deivisible by" << endl; //************Timeslice**************** cout << "How long is a time slice (in milliseconds): "; cin >> timeSlice; cout << endl; while(!cin || timeSlice < 1) { cout << "Invalid Input!" << endl; cout << "How long is a time slice (in milliseconds) "; cin.clear(); cin.ignore(100,'\n'); cin >> timeSlice; cout << endl; } cout << " A Timeslice is " << timeSlice << " milliseconds" << endl; cout << endl; //**************Printers************** cout << "How Many Printers would you like: "; cin >> printerNum; cout << endl; while(!cin || printerNum < 1) { cout << "Invalid Input!" << endl; cout << "How Many Printers: "; cin.clear(); cin.ignore(100,'\n'); cin >> printerNum; cout << endl; } cout << printerNum << " Printers added" << endl; cout << endl; //*************Disks*************** cout << "How Many Disks would you like: "; cin >> diskNum; cout << endl; while(!cin || diskNum < 1) { cout << "Invalid Input!" << endl; cout << "How Many Disks: "; cin.clear(); cin.ignore(100,'\n'); cin >> diskNum; cout << endl; } cout << diskNum << " Disks added" << endl; cout << endl; //**************Cylinders************** for (int i = 0; i < diskNum; i++) { cout << "How Many Cylinders does disk " << i + 1 << " have: "; int cylNum; cin >> cylNum; cout << endl; while(!cin || cylNum < 1) { cout << "Invalid Input!" << endl; cout << "How Many Cylinders: "; cin.clear(); cin.ignore(100,'\n'); cin >> cylNum; cout << endl; } cylinderNum.push_back(cylNum); } for (int i = 0 ; i < diskNum; i++) { cout << "Disk " << i+1 << " has " << cylinderNum[i] << " cylinders" << endl; } //cout << "Each Disk has " << cylinderNum << " Cylinders" << endl; cout << endl; //*************CDRW*************** cout << "How Many CD/RWs would you like: "; cin >> cdrwNum; cout << endl; while(!cin || cdrwNum < 1) { cout << "Invalid Input!" << endl; cout << "How Many CD/RWs: "; cin.clear(); cin.ignore(100,'\n'); cin >> cdrwNum; cout << endl; } cout << cdrwNum << " CD/RWs added" << endl; cout << endl; //*************MakeQueuesAndFrameList*************** for (int i = 0; i < printerNum+1; i++) { printers.push_back(printerQueue); } for (int i = 0; i < diskNum+1; i++) { disks.push_back(diskQueue); } for (int i = 0; i < cdrwNum+1; i++) { cdrws.push_back(cdrwQueue); } int totalFrames = totalMemSize / pageSize; activeRecord.first = false; for (int i = 0; i< totalFrames; i++) { frameList.push_back(activeRecord); } cout << "*************STARTING OS***************" << endl; //RUNNING***************************************** try { while (true) { try { userInput = ""; cout << "Commands examples: {A, S, t, T, p1, d2, c3, P3, D2, C1}" << endl; cout << '>' ; cin >> userInput; cout << endl; if (userInput == "q" || userInput == "Q") { throw -1; } //ADD PROCESSES***************************************** if (userInput == "A") { cout << "What is the size of the Process: "; cin >> processSize; cout << endl; while(!cin || processSize < 1 ) { cout << "Invalid Input!" << endl; cout << "Max Process Size is " << maxProcessSize << endl; cout << "What is the size of the Process: " << endl; cin.clear(); cin.ignore(100,'\n'); cin >> processSize; cout << endl; } if (processSize > maxProcessSize ) { cout << "Process is too large and has been rejected." << endl << endl; } else{ cout << " The Process Size is " << processSize << endl; cout << endl; PCB newProcess(systemPID); newProcess.setProcessSize(processSize); if ((usedMem + processSize) <= totalMemSize) { readyQueue.push_back(newProcess); cout << "Process added to ready queue" << endl << endl; if (processSize % pageSize == 0) { usedMem += processSize; freeMem = totalMemSize - usedMem; } else{ roundedProcessSize = ((processSize / pageSize) + 1) * pageSize; usedMem += roundedProcessSize; freeMem = totalMemSize - usedMem; } //usedMem += processSize; //freeMem = totalMemSize - usedMem; cout << "Free Memory: " << freeMem << endl; cout << "Used Memory: " << usedMem << endl << endl; int framesNeeded; if (processSize % pageSize == 0) { framesNeeded = processSize/pageSize; } else{ framesNeeded = (processSize/pageSize) + 1; } int i = 0; int j = 0; while (j < framesNeeded) { if (frameList[i].first == false) { frameList[i].first = true; frameList[i].second = readyQueue.back().getPID(); readyQueue.back().updateFrames(i); j++; } i++; } } else{ jobPool.push_back(newProcess); sort(jobPool.begin(), jobPool.end(), sortHelp); cout << "Process added to Job Pool" << endl << endl; cout << "Free Memory: " << freeMem << endl; cout << "Used Memory: " << usedMem << endl << endl; } systemPID++; } } //SNAPSHOTS***************************************** else if(userInput == "S"){ do{ cout << "Please choose the snapshot you'd like:" << endl; cout << "'r', 'p', 'd', 'c', or 'm' : "; cin >> userInput; cout << endl; } while (userInput != "r" && userInput != "p" && userInput != "d" && userInput != "c" && userInput != "m"); //READY QUEUE PRINT***************************************** if (userInput == "r") { cout << endl << "READY QUEUE" << endl; printListHeader(totalAveTerminatedCpuTime, freeMem, usedMem); for (int i = 0; i < readyQueue.size(); i++) { float aveBurst = 0; if (readyQueue[i].getCpuCount() > 0) { aveBurst = ((float)readyQueue[i].getTotalProcessTime())/readyQueue[i].getCpuCount(); } cout << left << " " << setw(5) << readyQueue[i].getPID() << left << "| " << setw(9) << "N/A" << left << "| " << setw(8) << "N/A" << left << "| " << setw(9) << "N/A" << left << "| " << setw(5) << "N/A" << left << "| " << setw(8) << "N/A" << left << "| " << setw(6) << "N/A" << left << "| " << setw(6) << readyQueue[i].getTotalProcessTime() << left << "| " << setw(10) << readyQueue[i].getAveBurstTime() << left << "| "; readyQueue[i].printFrames(); //cout << readyQueue[i].getPID() << endl; } cout <<" ---------------------------------------------------------------------------------------------"<<endl; cout << endl; cout << "Job Pool PID numbers: "; if (!jobPool.empty()) { for (int i = 0 ; i < jobPool.size(); i++) { cout << "PID " << jobPool[i].getPID() << " "; } } else{ cout << "Empty"; } cout << endl << endl; } //MEMORY PRINT***************************************** else if (userInput == "m") { cout << endl << "MEMORY INFORMATION" << endl << endl; cout << "-------------------" << endl; cout << left << "| " << setw(6) << "Frame " << left << "| " << setw(6) << "Process |" << endl; cout << "-------------------" << endl; for (int i = 0 ; i < frameList.size(); i++) { if (frameList[i].first == true) { cout << left << "| " << setw(6) << i << left << "| " << setw(7) << frameList[i].second << " |" << endl; //cout << "Frame | " << i << " Process |" << frameList[i].second << " |" << endl; } } cout << "-------------------" << endl << endl; cout << "Free Frames: "; for (int i = 0 ; i < frameList.size(); i++) { if (frameList[i].first == false) { cout << i << " "; } } cout << endl << endl; } //PRINTER QUEUE PRINT***************************************** else if (userInput == "p") { cout << endl << "PRINTER QUEUE" << endl; printListHeader(totalAveTerminatedCpuTime, freeMem, usedMem); for (int i = 1; i < printers.size(); i++) { cout << " --"<< "p" << i << endl; //<<"--------------------------------------------------------------------"<< endl; for (int j = 0; j < printers[i].size(); j++) { cout << printers[i][j]; } } cout <<" ---------------------------------------------------------------------------------------------"<<endl; cout << endl; } //DISK QUEUE PRINT***************************************** else if (userInput == "d") { cout << endl << "DISK QUEUE" << endl; printListHeader(totalAveTerminatedCpuTime, freeMem, usedMem); for (int i = 1; i < disks.size(); i++) { cout << " --"<< "d" << i << endl; //<<"--------------------------------------------------------------------" << endl; disks[i].printDiskQueue(); } cout <<" ---------------------------------------------------------------------------------------------"<<endl; cout << endl; } //CDRW QUEUE PRINT***************************************** else if (userInput == "c") { cout << endl << "CDRW QUEUE" << endl; printListHeader(totalAveTerminatedCpuTime, freeMem, usedMem); for (int i = 1; i < cdrws.size(); i++) { cout << " --"<< "c" << i << endl; //<<"--------------------------------------------------------------------" << endl; for (int j = 0; j < cdrws[i].size(); j++) { cout << cdrws[i][j]; } } cout <<" ---------------------------------------------------------------------------------------------"<<endl; cout << endl; } else{ throw userInput; } } //TERMINATE PROCESS***************************************** else if(userInput == "t"){ if (readyQueue.empty()) { cout << "The Ready Queue is empty" << endl << endl; } else{ readTimeSlice(readyQueue.front(), timeSlice); cout << "Terminating Process " << readyQueue.front().getPID() << endl; cout << "Total CPU time was " << readyQueue.front().getTotalProcessTime() << endl; terminatedProcessCount++; terminatedProcessTotalTime += readyQueue.front().getTotalProcessTime(); if (readyQueue.front().getProcessSize() % pageSize == 0) { usedMem = usedMem - readyQueue.front().getProcessSize(); freeMem = totalMemSize - usedMem; } else{ roundedProcessSize = ((readyQueue.front().getProcessSize() / pageSize) + 1) * pageSize; usedMem = usedMem - roundedProcessSize; freeMem = totalMemSize - usedMem; } cout << "Free Memory: " << freeMem << endl; cout << "Used Memory: " << usedMem << endl; vector<int> frames = readyQueue.front().getFrames(); for (int i = 0 ; i < frames.size() ; i++) { frameList[frames[i]].first = false; } readyQueue.pop_front(); cout << endl; totalAveTerminatedCpuTime = (float)terminatedProcessTotalTime/terminatedProcessCount; int i = 0; while (!jobPool.empty() && jobPool.front().getProcessSize() < freeMem ) { while (jobPool.back().getProcessSize() > freeMem && i < jobPool.size()) { jobPool.push_front(jobPool.back()); jobPool.pop_back(); i++; } if (jobPool.back().getProcessSize() < freeMem) { readyQueue.push_back(jobPool.back()); jobPool.pop_back(); cout << "Process " << readyQueue.back().getPID() << " added to Ready Queue" << endl; int framesNeeded; if (processSize % pageSize == 0) { framesNeeded = processSize/pageSize; } else{ framesNeeded = (processSize/pageSize) + 1; } int i = 0; int j = 0; while (j < framesNeeded) { if (frameList[i].first == false) { frameList[i].first = true; frameList[i].second = readyQueue.back().getPID(); readyQueue.back().updateFrames(i); j++; } i++; } if (readyQueue.back().getProcessSize() % pageSize == 0) { usedMem = usedMem + readyQueue.back().getProcessSize(); freeMem = totalMemSize - usedMem; } else{ roundedProcessSize = ((readyQueue.back().getProcessSize() / pageSize) + 1) * pageSize; usedMem += roundedProcessSize; freeMem = totalMemSize - usedMem; } cout << "Free Memory: " << freeMem << endl; cout << "Used Memory: " << usedMem << endl; i = 0; } sort(jobPool.begin(), jobPool.end(), sortHelp); } } } //MOVETOBACKOFQUEUE****************************** else if(userInput == "T"){ if (readyQueue.empty()) { cout << "The Ready Queue is empty" << endl << endl; } else{ cout << "Moving Process " << readyQueue.front().getPID() << " to back of the Ready Queue " << endl << endl; readyQueue.push_back(readyQueue.front()); readyQueue.pop_front(); readyQueue.back().updateProcessTime(timeSlice); cout <<"Total CPU Process time has been updated" << endl << endl; cout <<"Current CPU Time is " << readyQueue.back().getTotalProcessTime() << "ms for Process " << readyQueue.back().getPID() << endl; cout << endl; } } //KILL PROCESS ANYWHERE***************************************** else if(userInput[0] == 'K'){ userInput.erase(0,1); if (checkValidNum(userInput, systemPID - 1) || stoi(userInput) == 0) { PCB temp(-1); int i = 0; bool found = false; int searchPID = stoi(userInput); //READY QUEUE KILL*************************************** while (i < readyQueue.size() && found == false) { cout << "Searching Ready Queue" << endl; if (searchPID == readyQueue[i].getPID()) { temp = readyQueue[i]; readyQueue.erase(readyQueue.begin()+i); found = true; cout << "Found the Process in the Ready Queue" << endl << endl; if (i == 0) { readTimeSlice(temp, timeSlice); } } i++; } //PRINT KILL********************************************* if (found == false) { for (int i = 1; i < printers.size(); i++) { for (int j = 0; j < printers[i].size(); j++) { cout << "Searching Print Queues" << endl; if (searchPID == printers[i][j].getPID()) { temp = printers[i][j]; printers[i].erase(printers[i].begin() + j); found = true; cout << "Found the Process in the Print Queue" << endl << endl; } } } } //DISK KILL********************************************* if (found == false) { for (int i = 1; i < disks.size(); i++) { if (disks[i].findProcess(searchPID)) { temp = disks[i].killProcess(searchPID); } } } //CDRW KILL********************************************* if (found == false) { for (int i = 1; i < cdrws.size(); i++) { for (int j = 0; j < cdrws[i].size(); j++) { cout << "Searching CDRW Queue" << endl; if (searchPID == cdrws[i][j].getPID()) { temp = cdrws[i][j]; cdrws[i].erase(cdrws[i].begin() + j); found = true; cout << "Found the Process in the CDRW Queue" << endl << endl; } } } } //CLEAN UP FOR NON JOB POOL if (found == true) { //readTimeSlice(temp, timeSlice); cout << "Killing Process " << temp.getPID() << endl; cout << "Total CPU time was " << temp.getTotalProcessTime() << endl; terminatedProcessCount++; terminatedProcessTotalTime += temp.getTotalProcessTime(); if (temp.getProcessSize() % pageSize == 0) { usedMem = usedMem - temp.getProcessSize(); freeMem = totalMemSize - usedMem; } else{ roundedProcessSize = ((temp.getProcessSize() / pageSize) + 1) * pageSize; usedMem = usedMem - roundedProcessSize; freeMem = totalMemSize - usedMem; } cout << "Free Memory: " << freeMem << endl; cout << "Used Memory: " << usedMem << endl; vector<int> frames = temp.getFrames(); for (int i = 0 ; i < frames.size() ; i++) { frameList[frames[i]].first = false; } cout << endl; totalAveTerminatedCpuTime = (float)terminatedProcessTotalTime/terminatedProcessCount; i = 0; while (!jobPool.empty() && jobPool.front().getProcessSize() <= freeMem ) { while (jobPool.back().getProcessSize() > freeMem && i < jobPool.size()) { jobPool.push_front(jobPool.back()); jobPool.pop_back(); i++; } if (jobPool.back().getProcessSize() <= freeMem) { readyQueue.push_back(jobPool.back()); jobPool.pop_back(); cout << "Process " << readyQueue.back().getPID() << " added to Ready Queue" << endl; int framesNeeded; if (processSize % pageSize == 0) { framesNeeded = processSize/pageSize; } else{ framesNeeded = (processSize/pageSize) + 1; } int i = 0; int j = 0; while (j < framesNeeded) { if (frameList[i].first == false) { frameList[i].first = true; frameList[i].second = readyQueue.back().getPID(); readyQueue.back().updateFrames(i); j++; } i++; } if (readyQueue.back().getProcessSize() % pageSize == 0) { usedMem = usedMem + readyQueue.back().getProcessSize(); freeMem = totalMemSize - usedMem; } else{ roundedProcessSize = ((readyQueue.back().getProcessSize() / pageSize) + 1) * pageSize; usedMem += roundedProcessSize; freeMem = totalMemSize - usedMem; } cout << "Free Memory: " << freeMem << endl; cout << "Used Memory: " << usedMem << endl; i = 0; } sort(jobPool.begin(), jobPool.end(), sortHelp); } } //JOB POOL KILL********************************************* if (found == false) { for (int i = 0; i < jobPool.size(); i++) { if (searchPID == jobPool[i].getPID()) { cout << "Searching Job Pool" << endl; PCB temp = jobPool[i]; jobPool.erase(jobPool.begin() + i); found = true; cout << "Found the Process in the Job Pool" << endl << endl; cout << "Killing Process " << temp.getPID() << endl << endl; terminatedProcessCount++; } } } if (found == false) { cout << "PID not found" << endl << endl; } } else{ cout << "PID does not exist" << endl << endl; } } //ADD TO PRINTER QUEUE***************************************** else if(userInput[0] == 'p'){ userInput.erase(0,1); if (checkValidNum(userInput, printerNum)) { if (!readyQueue.empty()) { readyQueue.front().fillPCB('p', false, 0,pageSize); printers[stoi(userInput)].push_back(readyQueue.front()); readyQueue.pop_front(); readTimeSlice(printers[stoi(userInput)].back(), timeSlice); printers[stoi(userInput)].back().increaseCpuCount(); } else{ cout << "There are no available processes in the Ready Queue" << endl; cout << "Please populate the Ready Queue and try again" << endl << endl; } } else{ cout << "Printer does not exist" << endl << endl; } } //ADD TO DISK QUEUE***************************************** else if(userInput[0] == 'd'){ userInput.erase(0,1); if (checkValidNum(userInput,diskNum)) { if (!readyQueue.empty()) { readyQueue.front().fillPCB('d', true, cylinderNum[stoi(userInput)-1], pageSize); readTimeSlice(readyQueue.front(), timeSlice); readyQueue.front().increaseCpuCount(); disks[stoi(userInput)].push_back(readyQueue.front()); readyQueue.pop_front(); } else{ cout << "There are no available processes in the Ready Queue" << endl; cout << "Please populate the Ready Queue and try again" << endl << endl; } } else{ cout << "Printer does not exist" << endl << endl; } } //ADD TO CDRW QUEUE***************************************** else if(userInput[0] == 'c'){ userInput.erase(0,1); if (checkValidNum(userInput,cdrwNum)) { if (!readyQueue.empty()) { readyQueue.front().fillPCB('c', false, 0, pageSize); cdrws[stoi(userInput)].push_back(readyQueue.front()); readyQueue.pop_front(); readTimeSlice(cdrws[stoi(userInput)].back(), timeSlice); cdrws[stoi(userInput)].back().increaseCpuCount(); } else{ cout << "There are no available processes in the Ready Queue" << endl; cout << "Please populate the Ready Queue and try again" << endl << endl; } } else{ cout << "CDRW does not exist" << endl << endl; } } //REMOVE FROM PRINTER QUEUE***************************************** else if(userInput[0] == 'P'){ userInput.erase(0,1); if (userInput.length()<1) { throw userInput; } if (checkValidNum(userInput, printerNum)) { if (printers[stoi(userInput)].empty()) { cout << "Printer Queue is empty" << endl << endl; } else{ readyQueue.push_back(printers[stoi(userInput)].front()); printers[stoi(userInput)].pop_front(); cout << "Printer Interrupt Handled" << endl << endl; } } else{ cout << "Printer does not exist" << endl << endl; } } //REMOVE FROM DISK QUEUE***************************************** else if(userInput[0] == 'D'){ userInput.erase(0,1); if (userInput.length()<1) { throw userInput; } if (checkValidNum(userInput, diskNum)) { if (disks[stoi(userInput)].empty()) { cout << "Disk Queue is empty" << endl << endl; } else{ readyQueue.push_back(disks[stoi(userInput)].front()); disks[stoi(userInput)].pop_front(); cout << "Disk Interrupt Handled" << endl << endl; } } else{ cout << "Disk does not exist" << endl << endl; } } //REMOVE FROM CDRW QUEUE***************************************** else if(userInput[0] == 'C'){ userInput.erase(0,1); if (userInput.length()<1) { throw userInput; } if (checkValidNum(userInput, cdrwNum)) { if (cdrws[stoi(userInput)].empty()) { cout << "CDRW Queue is empty" << endl << endl; } else{ readyQueue.push_back(cdrws[stoi(userInput)].front()); cdrws[stoi(userInput)].pop_front(); cout << "CD/RW Interrupt Handled" << endl << endl; } } else{ cout << "CDRW does not exist" << endl << endl; } } else{ throw userInput; } } catch (string) { cout << "Input error: Please try again" << endl << endl; } //cout << endl; }