I'm making a rough draft just to train if
and else
that will be a subject in my next college class. I want to get there and at least already have a base of what the teacher will teach.
My question is as follows.
When I ask the user to type s
(Yes) or n
(No) to show the table works, however if the user types the S
in uppercase the IDE executes the block of else
.
How do I get the user to only type uppercase in printf
?
Follow the code below.
#include <stdio.h>
#include <stdlib.h>
main(){
int num;
char sn;
printf("DESEJA ABRIR A TABUADA? S/N: ");
scanf("%c", &sn);
if(sn=='s') {
printf("\nDIGITE O NUMERO DA TABUADA QUE DESEJA: ");
scanf("%d", &num);
printf("\n%d x 1 = %d\n", num , num*1);
printf("%d x 2 = %d\n", num , num*2);
printf("%d x 3 = %d\n", num , num*3);
printf("%d x 4 = %d\n", num , num*4);
printf("%d x 5 = %d\n", num , num*5);
printf("%d x 6 = %d\n", num , num*6);
printf("%d x 7 = %d\n", num , num*7);
printf("%d x 8 = %d\n", num , num*8);
printf("%d x 9 = %d\n", num , num*9);
printf("%d x 10 = %d\n\n", num , num*10);
}
else
printf("\nOK, PROGRAMA FINALIZADO.\n\n");
system("pause");
}