I'm writing a program in which I read in four matrices (A, B, C, D) and four commands and operate those commands. One of the commands is to add two matrices. The command reads in like this :
a A B
The 'a' tells the program it will be adding together two matrices and the letters following tell which matrices it will be adding from the four matrices. I wrote a switch to read in the matrices letters after the command. This is the switch:
Code:
switch (matrix1)
{
case 'A' :
readfileA (fin, matrixA);
break;
case 'B' :
readfileB (fin, matrixB);break;
case 'C' :
readfileC (fin, matrixC);break;
case 'D' :
readfileD (fin, matrixD);break;
default :
cout<<"Not a valid Matrix"<<endl;
}
switch (matrix2)
{
case 'A' :
readfileA (fin, matrixA);break;
case 'B' :
readfileB (fin, matrixB);break;
case 'C' :
readfileC (fin, matrixC);break;
case 'D' :
readfileD (fin, matrixD);break;
default :
cout<<"Not a valid Matrix"<<endl;
}
In the command 'a A B' it goes to case 'A' for matrix1 and case 'B' for matrix two. So now I need to add the two together, which I know how to do. The problem I'm having is how to say in each case that what ever matrix the command lists first needs to change to matrix1 and whatever the command lists second needs to change to matrix2 so that I can add them together using these names. I need to do this so that I can easily add together the matrices that the command lists no matter what they are. I know that I could use if/else statements but then I would have to go through every possibility of combinations and that would be a lot of extra code.
So if the command is 'a A B' I need case 'A' to change matrixA to matrix1 and case 'B' to change matrixB to matrix2.
Please bear with me, I am a beginner programmer so this may be an easy fix for some but I just can't figure it out! Any kind of info would help. If you don't understand what I'm trying to do then ask and I can try to clarify. Thank You!