-1

I think it has something to do with with either the second scanf function or the if/else statements.

#include <stdio.h>

int main()

{
int n1;
int n2;
char op;

printf("insert first number: ");
scanf("%d", &n1);


printf("Insert operation (+, -, *, /): ");
scanf("%c", &op);


printf("insert second number: ");
scanf("%d", &n2);

if(op='+')
{
    printf("%d + %d = %d", n1, n2, n1+n2);
}
else if(op='-')
{
    printf("%d - %d = %d", n1, n2, n1-n2);
}
else if(op='*')
{
    printf("%d * %d = %d", n1, n2, n1*n2);
}
else if(op='/')
{
    printf("%d / %d = %d", n1, n2, n1/n2);
}
else
{
    printf("error [use +, -, *, /]");
}

when i run it it waits for me to input the first number, then prints the second prompt but instead of waiting for me to input the operation it skips straight to printing the third prompt and i can't figure out why.

1 Answers1

-2

Try this instead. Try this coding in switch case. You will be getting expected results. use switch(ch); and break after each cases.