Wt happened is just i have made a very simple menu driven programme and in that programme wen i use character not matching wid d switch cases , it runs twice...i want it to run once only..i know its becoz getchar(); but y???
#include<stdio.h>
#include<conio.h>
void even_odd();
int n;
void main()
{
char ch;
clrscr();
do
{
printf("\n1. please print hi");
printf("\n2. please print hello");
printf("\n3. exit d programme");
printf("\n enter ur choice");
printf("\n");
ch=getchar();
}while(ch!='1'&& ch!='2'&& ch!='3');
switch(ch)
{
case '1':
printf("enter a number");
scanf("%d", &n);
even_odd();
break;
case '2':
printf("hello");
break;
case '3':
exit(1);
}
getch();
}
void even_odd()
{
if(n%2==0)
printf("its even");
else
printf("its odd");
}