if statement inside switch case doesn't work

Hi all! Could you explain and help me? after i input "a" and then going to ask again, well it does not print the number. BTW, i am using turbo c for school purposes.

[code]
#include<stdio.h>
#include<conio.h>

int main()
{
clrscr();

char choice;
int c1=0;

printf("Enter the letter a:");
getchar();
scanf("%c",&choice);


switch(choice)
{

default:printf("wrong");

case 'A': case 'a':

clrscr();

printf("Enter letter:");
scanf("%d",&c1);

if((c1==1))
{
printf("1");
}

if((c1==2))
{
printf("2");
}

}
getch();
}/code]
Why not go on the cprogramming board?
1
2
3
printf("Enter the letter a:");
getchar();
scanf("%c",&choice);

getchar() reads one character. scanf() reads one more. This means you're reading the second character into choice.

You need a break statement at the end of the default case. Otherwise program control falls through to the case 'A' case 'a' case.
@poteto, what is that?

@dhayden. Now it's okay. Is it bad for using scanf with getchar at the same time?
Topic archived. No new replies allowed.