Iam facing a problem in Switch statement. The problem is that i will ask to integer from the user & if the user want to "+" , "-" or "*" operator the switch case will work but in my coing it only ask the two interger values from the user but did not take any input from the user that he want "+" ,"-" or "*" with the operator.
it simply skip it & go to the default case..
The compliler is not showing any error in th ebelow program my out put is also given below...please guide me how where is the logical error...
#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2,res;
char operator;
clrscr();
printf("\n\tPlease enter 1st integer : ");
scanf("%d",&num1);
printf("\n\tPlease enter 2nd integer : ");
scanf("%d",&num2);
printf("\n\tEnter what u want to Manupulate ");
scanf("%c",&operator);
switch(operator)
{
case '+':
printf("\n\tThe result is %d,%c,%d=%d",num1,operator,num2,res);
break;
case '-':
printf("\n\tThe result is %d,%c,%d=%d",num1,operator,num2,res);
break;
case '*':
printf("\n\tThe result is %d,%c,%d=%d",num1,operator,num2,res);
break;
default:
printf("\n\tNothing...");
}
getch();
}
*****************OUT PUT OF THE PROGRAM**************
Please enter 1st integer : 5
Please enter 2nd integer : 5
Enter what u want to Manupulate
Nothing...