Nested if / else structures and switch

#include <stdio.h> int main(){ // Al insertar en consola un numero que nos devuelva el nombre del dia correspondiente, 1= lunes, 2=martes etc int x; printf("Coloca un numero del 1 al 4 para saber que dia devuelve. \n"); scanf("%i", &x); //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Ifs/else anidadas^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if(x == 1){ printf("Lunes. \n"); }else if(x == 2){ printf("Martes. \n"); }else if(x == 3){ printf("Miercoles. \n"); }else if(x == 4){ printf("Jueves. \n"); }else{ printf("El numero que a ingresado no esta entre el 1 y el 4 \n"); } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Termino ifs/else anidadas^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Switchs^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ float y; printf("Coloca un numero que tenga coma o sea que no sea entero entre el 1.4 y el 1.8"); scanf("%i", &x); switch(x){ case 1: printf("Lunes \n");break; case 2: printf("Martes \n");break; case 3: printf("Miercoles \n");break; case 4: printf("Jueves \n");break; case 5: printf("Viernes \n"); break; } system("pause"); return 0; }
I am beginner in c and well, the comments are in Spanish since I am from Latin America ...
In this snippet I am demonstrating what I am learning at the moment, which can help someone beginner like me

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.