#include<stdio.h>
#include<conio.h>
                 void main(){
                      char x;
                      int result,a,b;
                      
                      printf("type the first number\n");
                      scanf("%d",&a);
                      
                      printf("enter the operand\n");
                      scanf("%d",&x);
                      
                      printf("type the second number\n");
                      scanf("%d",&b);
                      
                      
                      switch(x){
                                case '+':
                                result=a+b;
                                printf("value is:%d",result);
                                break;
                                
                                case '-':
                                result=a-b;
                                printf("value is:%d",result);
                                break;
                                
                                case '*':
                                result=a*b;
                                printf("value is:%d",result);
                                break;
                                
                                case '/':
                                result=a/b;
                                printf("value is:%d",result);
                                break;
                                
                                case '%':
                                result=a%b;
                                printf("value is:%d",result);
                                break;
                                
                                default:
                                        printf("you entered the wrong operation");
                                        break;
                                        
                                        }
                                
                                getch();        
                                        }

this code doesnt execute


please tell me where have i gone wrong ...thank you

Maybe you could elaborate on 'this code doesn't execute'.

Maybe you could elaborate on 'this code doesn't execute'.

I think it's the next evolution of "it doesn't work". :D

And the problem is with a call to scanf():

scanf("%d",&x);

Which should be this:

scanf(" %c",&x);

Note the leading space in the format string. This forces scanf() to ignore leading whitespace before looking for a character. %c is one of the specifiers that doesn't do that normally, which means it would normally pick up the '\n' character left over from the previous call to scanf().

scanf("%s",&x);

i think it's suitable....

scanf("%s",&x);

i think it's suitable....

x is a char, not an array. There's insufficient space to hold both the character typed and the '\0' character that scanf() adds automatically.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.