Lo pasé un poco a C++.
Siempre me dice programa terminado.
Código modificado un poco.
Código:
#include <iostream>
#include <windows.h> // Para mostrar texto en el título de la ventana.
#include <stdio.h> // Cambio color de fondo y letras.
#include <tchar.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
//using std::cout;
//using std::cin;
// Función posición del cursor.
void gotoxy(int ancho_x, int alto_y)
{
HANDLE hcon;
hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos{};
dwPos.X = ancho_x;
dwPos.Y = alto_y;
SetConsoleCursorPosition(hcon, dwPos);
}
int Menu_Principal(void);
int _tmain(int argc, _TCHAR* argv[])
{
int valor = 0;
valor = Menu_Principal();
cout << "\r\n\r\nSe selecciono la opcion %d del Menu Principal", valor;
cout << "\r\nEl programa ha terminado";
//getch(); //Esperamos pulsacion de tecla para terminar y cerrar ventana de consola
exit(0);
}
int Menu_Principal(void)
{
#pragma region "Configuración ventana."
// Mostrar caracteres correctamente en pantalla y título de la ventana.
SetConsoleOutputCP(65001);
wchar_t titulo[128];
MultiByteToWideChar(CP_UTF8, 0, "Título de la ventana", -1, titulo, 128);
SetConsoleTitleW(titulo);
// Tamaño de la pantalla. Se cambia en los dos últimos dígitos.
SMALL_RECT r = { 0, 0, 80, 20 }; // X = 80, Y = 20.
SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &r);
// Cambio color de 6 (amarillo / naranja), color letras 0 (negro).
system("color 60");
// Ocultar cursor.
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cci);
cci.bVisible = 0; // 0 oculta. 1 muestra cursor.
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cci);
#pragma endregion
char opcion = ' ';
INICIO_MENU:
//textattr(2);
//clrscr();
gotoxy(10, 8); cout << " oOo[ MENU PRINCIPAL ]oOo ";
gotoxy(10, 10); cout << "[1].- ALTAS";
gotoxy(10, 11); cout << "[2].- BAJAS";
gotoxy(10, 12); cout << "[3].- MODIFICACIONES";
gotoxy(10, 13); cout << "";
gotoxy(10, 14); cout << "[0].- SALIR";
gotoxy(10, 16); cout << "INTRODUCE OPCION: ";
//opcion = getch(); //ten en cuenta que si tomamos con getch solo podemos coger 1 caracter
// o sea numeros de 0 al 9 y algun caracter del Abecedario
cin >> opcion;
if (opcion == '1') {
//Llamamos a funcion que corresponda
return(1);
}
else if (opcion == '2') {
//Llamamos a funcion que corresponda
return(2);
}
else if (opcion == '3') {
//Llamamos a funcion que corresponda
return(3);
}
else if (opcion == '0') {
return(0);
}
else {
gotoxy(10, 16); cout << "OPCION NO VALIDA - Pulse una tecla para continuar...";
//getch();
goto INICIO_MENU;
}
}
En cuantoal goto, cuanto menos se uses mejor. Prohibido usar Goto me decía mi profesor a toda la clase que éramos unos casi 30 alumnos.