I am trying to learn C++ and so far i have been on the right but i have been have a simple problem and i am getting confused on the case statement i have known how to deal with the if statement and i understand it very well,i working classes and methods in my code below which works perfectly i want to know how i can change this if statement and replace it with the case statement,when i try it its not working but this is my code for the if statement how can i make it work if i want to use case instead of if??thanks in advance
my code
void SetType(){
cout<<"Book SetType"<<endl;
Choice:
cout<<"Please Select from the list: \n 1- Technical literature \n 2- Fiction literature \n 3- Textbook"<<endl;
int i;
cin >> i;
if ((i>0)&(i<=3)) {
if (i==1) Type="Technical literature";
if (i==2) Type="Fiction literature";
if (i==3) Type="Textbook";
}
else
{
cout << "Erorr you entered a wrong choice" << endl;
goto Choice;
}
}
1 Answer