I wrote a certain method on how to access my fields in a class, but my teacher told me I should use an enum.
How can I re-write this code to use an enum and not use gotos?
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;
switch (i) {
case 1:
Type = "Technical literature";
break;
case 2:
Type = "Fiction literature";
break;
case 3:
Type = "Textbook";
break;
default:
cout << "Erorr you entered a wrong choice" << endl;
goto Choice;
}
}
if (std::cin >> i) { ... }goto, put the whole stuff in an appropriate loop instead. @kenny's answer addresses both.