I have 2 models of code here, please note:
Template 1 (using 'do while'):
int main(){
char opc;
do{
std::cout << "|============|\n";
std::cout << "|Escrever.[1]|\n";
std::cout << "|Ler......[2]|\n";
std::cout << "|============|\n\n";
std::cout << "Oque deseja fazer?";
std::cin >> opc;
std::cin.ignore();
system("cls");
switch(opc){
case '1':
escreve();
case '2':
leitura();
default:
std::cout << "Opção incorreta!\n\n";
}
}while(opc!='1' || opc!='2');
return 0;
}
Template 2 (using recursion):
int main(){
char opc;
std::cout << "|============|\n";
std::cout << "|Escrever.[1]|\n";
std::cout << "|Ler......[2]|\n";
std::cout << "|============|\n\n";
std::cout << "Oque deseja fazer?";
std::cin >> opc;
std::cin.ignore();
system("cls");
switch(opc){
case '1':
escreve();
case '2':
leitura();
default:
std::cout << "Opção incorreta!\n\n";
main();
}
return 0;
}
Doubt: Which of the two would be the ideal one to use?