you may use getch() instead of getchar(), getch() is included in conio.h
example:
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
printf("Press something.\n");
getch();
printf("Done something.\n");
getch();
return 0;
}
karthigayan, if you dont mind, i will use your code in this example.
you should use a WHILE loop in here, here is an example:
Code:
#include<stdio.h>
#include<conio.h>
main()
{
int op;
printf("Please Enter the option ( 1 / 2 / 3 ) : ");
while(op != 1 && op != 2 && op != 3)
{
scanf("%d",&op);
switch(op)
{
case 1:
printf( "You have entered one \n" );
break;
case 2:
printf( "You have entered two \n" );
break;
case 3:
printf( "You have entered three \n" );
break;
default:
printf( "Try again\n" );
}
}
}
if this seems confusing, the != sign means if 'not equal'. so if OP is
not 1 nor 2 or 3, then that means the user typed an incorrect number
so the loop keeps going. however, if OP is equal to either 1, 2, or 3
then the loop exits. simple, eh?
Cheers, ComputerWarrior.