I have a switch statement menu with the following requirements:
"GetNewMatrix " as an enumeration option with being a number from 0 to 9.
The users input MUST be all on one line.
Enumeration MUST be used.
I need the user to be able to input something like "GetNewMatrix 5" and have the switch statement see the GetNewMatrix to initiate that case as well as pass the 5 down into the case for initialization of matrix[5].MatrixType()
I'm quite lost on how exactly to implement this. I currently have the following (quite rough) code down though this does not help me extract the users integer from their input as it needs to be done in all one line as stated above.
matrix is an array of size [10] of Class MatrixType which holds int values[MAX_ROWS][MAX_COLS], int numRows, and int numCols
input is a string used to get the users input and compare it to enum cases to decide what case to go forward with
name is an integer that is between 0 and 9 and used to label the Matrix in an array of [10]
r is an integer used to save the user specified row count
c is an integer used to save the user specified column count
enum Choice {Start, GetNewMatrix, AddMatrices, SubMatrices, MultiplyMatrices, PrintMatrix, Quit}; Choice ch = Start; while(ch != Quit) { cout << "=======================================================" << endl; cout << "GetNewMatrix # (Create a new Matrix)" << endl; cout << "AddMatrices # # # (Adds two matrices together)" << endl; cout << "SubMatrices # # # (Subtracts a second matrix from the first)" << endl; cout << "MultiplyMatrices # # # (Multiplies two matrices together)" << endl; cout << "PrintMatrix # (Print out a matrix)" << endl; cout << "Quit (Quit the program)" << endl; cout << "=======================================================" << endl << endl; cout << "Please enter your choice here: "; cin >> input; //Unable to assign ch to a string if (input == "GetNewMatrix") { ch = GetNewMatrix; } else if (input == "Quit") { ch = Quit; } else { cout << "Unknown entry. Please use exact capitalization." << endl; } switch(ch) { case GetNewMatrix: //Placeholder until integer extraction is figured out cout << "Please enter a value (between 0 and 9) to name the matrix: "; cin >> name; matrix[name].MatrixType(); cout << "Matrix " << name << " created." << endl; cout << "Please enter values (between 1 and 10) for row and column size: "; cin >> r >> c; matrix[name].SetSize(r - 1,c - 1); cout << "Matrix size set to " << r << " x " << c << endl; break;