printf("Enter num1: ");
scanf("%d", &num1);
getchar();
printf("Enter Operator: ");
scanf("%c", &op);
printf("Enter num2: ");
scanf("%f", &num2);
I hope that tells you where the problems are. The first scanf should look like the last one there and use the
"%f"
format string.
If I were you, I would write the last part like this :
double result = 0;
int valid = 1;
if( op == '+' ) {
result = num1 + num2;
} else if( op == '-' ) {
result = num1 - num2;
} else if( op == '/' ) {
result = num1 / num2;
} else if( op == '*' ) {
result = num1 * num2;
} else {
printf( "Invalid Operator\n" );
valid = 0;
}
if( valid )
printf( "result is %f\n", result );