You had syntax errors in switch
and logic error in the conditions of do while
. More than that I added code to validate that only numbers are entered. I leave the code corrected. Greetings!
#include <stdlib.h>
#include <stdio.h>
int mes;
int main()
{
do
{
printf("\n\n Introduce un numero del 1 al 12 correspondiente al mes de tu eleccion: ");
char *p, s[100];
while (fgets(s, sizeof(s), stdin)) {
mes = strtol(s, &p, 10);
if (p == s || *p != '\n') {
printf("Solo debe ingresar numeros. Por favor, ingrese nuevamente una opcion: ");
} else break;
}
switch (mes)
{
case 1 : printf( "\n\n Enero.");
break;
case 2 : printf( "\n\n Febrero.");
break;
case 3 : printf( "\n\n Marzo.");
break;
case 4 : printf( "\n\n Abril.");
break;
case 5 : printf( "\n\n Mayo.");
break;
case 6 : printf( "\n\n Junio.");
break;
case 7 : printf( "\n\n Julio.");
break;
case 8 : printf( "\n\n Agosto.");
break;
case 9 : printf( "\n\n Septiembre.");
break;
case 10 : printf( "\n\n Octubre.");
break;
case 11 : printf( "\n\n Noviembre.");
break;
case 12 : printf( "\n\n Diciembre.");
break;
default: printf( "\n\n ERROR: Ingresaste una opcion no existente." );
break;
}
} while (mes < 1 || mes > 12 );
return 0;
}