I'm trying to write a program that has a menu with a switch statement.
I'm getting "case label'1' not within a switch statement" and subsequent errors for the other two choices and the default.
What am I doing wrong?
Thanks for any help!
int main(){
int choice;
Matrix A,B,C;
cout <<"What would you like to do? "<< endl;
cout <<"1 - Add" << endl;
cout <<"2 - Multiply" << endl;
cout <<"0 - Exit" << endl;
cin>>choice
switch(choice){
case 1 :
A.input();
A.display();
B.input();
B.display();
C.addMatrix(A,B,C);
C.display();
break;
case 2 :
A.input();
A.display();
B.input();
B.display();
C.multiplyMatrix(A,B,C);
C.display();
break;
case 0 :
cout<<"Bye!\n";
break;
default:
cerr<<"You must choose 0,1 or 2.\n";
break;
}
return 0;
}
Good eye.
I did add that since posting this.
Still getting the errors.
While working on this more, I now have the following errors during compiling:
Matrix2.cpp:162: `choice' undeclared (first use this function)
Matrix2.cpp:162: (Each undeclared identifier is reported only once for each function it appears in.)
And this is what the code looks like now:
int main(){
Matrix A,B,C;
int choice;
while(choice!=0){
cout <<"What would you like to do? "<< endl;
cout <<"1 - Add" << endl;
cout <<"2 - Multiply" << endl;
cout <<"0 - Exit" << endl;
cin>>choice; <------------------------This is the one causing the error
switch(choice){
case 1:
A.input();
A.display();
B.input();
B.display();
C.addMatrix(A,B,C);
C.display();
break;
case 2:
A.input();
A.display();
B.input();
B.display();
C.multiplyMatrix(A,B,C);
C.display();
break;
case 0:
cout<<"Bye!\n";
break;
default:cerr<<"You must choose 0,1 or 2.\n";
break;
}
}
}