c - Why is my '+' operator considered as a new line character? -


the following code modular calculator problem. input data is:

  5 +3 * 7 +10 * 2 * 3 +1 % 11 
#include <stdio.h>  int main(void) {     char oper;     int number,result;     scanf("%d",&number);     result=number;         {         oper=getchar();         fflush(stdin);         scanf("%d",&number);         if(oper=='+')         {             result=result+number;         }         else if(oper=='*')         {             result=result*number;         }         printf("%c %d %d ",oper,number,result);     }while(oper!='%');     result=result%number;     printf("%d",result);     return 0; } 

the output follows:

3 5   3 5 * 7 35   10 35   10 35 * 2 70   2 70 * 3 210   1 210   1 210 % 11 210 1 

i can't seem figure out why?

replace

oper=getchar(); fflush(stdin); scanf("%d",&number); 

with

scanf(" %c", &oper); scanf("%d", &number); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -